/**
 * @file Bsp.c
 * @author 徐松亮 (5387603@qq.com)
 * @version 1.0
 * @date 2023-09-28
 *
 * @copyright Copyright (c) {2030}  沈阳迈思医疗科技有限公司
 *
 * @brief 驱动层-->根据应用需求定义实体与初始化
 */
/* 私有头部文件 (Includes)-----------------------------------------------------*/
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include "Bsp.h"
/* 编译警告条件 (Compile warning condition)------------------------------------*/
#if (defined(PROJECT_TEST_BSP))
#warning Please Set Effective Project to Bsp.h
#endif
/* 私有类型定义 (Private typedef)----------------------------------------------*/
/* 私有型宏定义 (Private define)-----------------------------------------------*/
/* 私有常量定义 (Private constants)--------------------------------------------*/
/* 公有常量定义 (Public constants)---------------------------------------------*/
/* 私有变量定义 (Private variables)--------------------------------------------*/
static uint8_t uc_LedDebugEnable = 0;
static uint8_t uc_DebugTestEnable = 0;
static char *ucp_BootVerStr = (char *)MEM_256B_BLK_ADDR_BEGIN;
static char *ucp_BootResetFlag = (char *)(MEM_256B_BLK_ADDR_BEGIN + 16);
/**
 * @bug:目前以下内容不好使(与使用Boot相关，跳转后标致都清空啦)
 */
static uint16_t us_ResetCmt_SFR = 0;
static uint16_t us_ResetCmt_IWDG = 0;
static uint16_t us_ResetCmt_PIN = 0;
static uint16_t us_ResetCmt_LPWR = 0;
static uint16_t us_ResetCmt_BOR = 0;
/* 公有变量定义 (Public variables)---------------------------------------------*/
/// Boot版本号
char Bsp_BootVerStr[12] = {0};
/// ADC采集数据
#if (defined(STM32H743xx))
ALIGN_32BYTES(__attribute__((section(".RAM_D3")))
              uint16_t BspAdc1_DmaBuf[BSP_ADC1_DMA_CHANNEL_MAX]);
ALIGN_32BYTES(__attribute__((section(".RAM_D3")))
              uint16_t BspAdc3_DmaBuf[BSP_ADC3_DMA_CHANNEL_MAX]);
#else
uint16_t BspAdc1_DmaBuf[BSP_ADC1_DMA_CHANNEL_MAX] = {0};
uint16_t BspAdc3_DmaBuf[BSP_ADC3_DMA_CHANNEL_MAX] = {0};
#endif
int8_t BspAdc_CpuTemp = 0;
uint16_t BspAdc_Vrefint_mv = 0;
uint16_t BspAdc_Vbat_mV = 0;
uint8_t BspAdc_DebugTest_Enable = 0;
/// 串口
ALIGN_32BYTES(__attribute__((section(".RAM_D3"))) uint8_t LpUart_Rx1Buf[BSP_LPUART_1_RXBUF_SIZE]);
ALIGN_32BYTES(__attribute__((section(".RAM_D3"))) uint8_t LpUart_Tx1Buf[BSP_LPUART_1_TXBUF_SIZE]);
ALIGN_32BYTES(__attribute__((section(".RAM_D3"))) uint8_t Uart_Rx1Buf[BSP_UART_1_RXBUF_SIZE]);
ALIGN_32BYTES(__attribute__((section(".RAM_D3"))) uint8_t Uart_Tx1Buf[BSP_UART_1_TXBUF_SIZE]);
// ALIGN_32BYTES(__attribute__((section(".RAM_D3"))) uint8_t Uart_Rx2Buf[BSP_UART_2_RXBUF_SIZE]);
// ALIGN_32BYTES(__attribute__((section(".RAM_D3"))) uint8_t Uart_Tx2Buf[BSP_UART_2_TXBUF_SIZE]);
ALIGN_32BYTES(__attribute__((section(".RAM_D3"))) uint8_t Uart_Rx3Buf[BSP_UART_3_RXBUF_SIZE]);
ALIGN_32BYTES(__attribute__((section(".RAM_D3"))) uint8_t Uart_Tx3Buf[BSP_UART_3_TXBUF_SIZE]);
// ALIGN_32BYTES(__attribute__((section(".RAM_D3"))) uint8_t Uart_Rx4Buf[BSP_UART_4_RXBUF_SIZE]);
// ALIGN_32BYTES(__attribute__((section(".RAM_D3"))) uint8_t Uart_Tx4Buf[BSP_UART_4_TXBUF_SIZE]);
// ALIGN_32BYTES(__attribute__((section(".RAM_D3"))) uint8_t Uart_Rx5Buf[BSP_UART_5_RXBUF_SIZE]);
// ALIGN_32BYTES(__attribute__((section(".RAM_D3"))) uint8_t Uart_Tx5Buf[BSP_UART_5_TXBUF_SIZE]);
ALIGN_32BYTES(__attribute__((section(".RAM_D3"))) uint8_t Uart_Rx6Buf[BSP_UART_6_RXBUF_SIZE]);
ALIGN_32BYTES(__attribute__((section(".RAM_D3"))) uint8_t Uart_Tx6Buf[BSP_UART_6_TXBUF_SIZE]);
// ALIGN_32BYTES(__attribute__((section(".RAM_D3"))) uint8_t Uart_Rx7Buf[BSP_UART_7_RXBUF_SIZE]);
// ALIGN_32BYTES(__attribute__((section(".RAM_D3"))) uint8_t Uart_Tx7Buf[BSP_UART_7_TXBUF_SIZE]);
ALIGN_32BYTES(__attribute__((section(".RAM_D3"))) uint8_t Uart_Rx8Buf[BSP_UART_8_RXBUF_SIZE]);
ALIGN_32BYTES(__attribute__((section(".RAM_D3"))) uint8_t Uart_Tx8Buf[BSP_UART_8_TXBUF_SIZE]);
BSP_UART_T_INTERFACE Bsp_t_LpUart = {0};
BSP_UART_T_INTERFACE Bsp_t_Uart1 = {0};
BSP_UART_T_INTERFACE Bsp_t_Uart3 = {0};
BSP_UART_T_INTERFACE Bsp_t_Uart6 = {0};
BSP_UART_T_INTERFACE Bsp_t_Uart8 = {0};
extern UART_HandleTypeDef hlpuart1;
extern DMA_HandleTypeDef hdma_lpuart1_tx;
extern DMA_HandleTypeDef hdma_lpuart1_rx;
extern UART_HandleTypeDef huart1;
extern DMA_HandleTypeDef hdma_usart1_tx;
extern DMA_HandleTypeDef hdma_usart1_rx;
// extern UART_HandleTypeDef huart2;
// extern DMA_HandleTypeDef hdma_usart2_tx;
// extern DMA_HandleTypeDef hdma_usart2_rx;
extern UART_HandleTypeDef huart3;
extern DMA_HandleTypeDef hdma_usart3_tx;
extern DMA_HandleTypeDef hdma_usart3_rx;
// extern UART_HandleTypeDef huart4;
// extern DMA_HandleTypeDef hdma_uart4_tx;
// extern DMA_HandleTypeDef hdma_uart4_rx;
// extern UART_HandleTypeDef huart5;
// extern DMA_HandleTypeDef hdma_uart5_tx;
// extern DMA_HandleTypeDef hdma_uart5_rx;
extern UART_HandleTypeDef huart6;
extern DMA_HandleTypeDef hdma_usart6_tx;
extern DMA_HandleTypeDef hdma_usart6_rx;
// extern UART_HandleTypeDef huart7;
// extern DMA_HandleTypeDef hdma_uart7_tx;
// extern DMA_HandleTypeDef hdma_uart7_rx;
extern UART_HandleTypeDef huart8;
extern DMA_HandleTypeDef hdma_uart8_tx;
extern DMA_HandleTypeDef hdma_uart8_rx;
/// 数据结构实体---观察点
BSP_DWT_T_INTERFACE Bsp_t_Dwt;
/// 数据结构实体---GPIO-IIC
BSP_GPIO_IIC_T_INTERFACE Bsp_t_GpioIIC_Eeprom = {0};
BSP_GPIO_IIC_T_INTERFACE Bsp_t_GpioIIC_SDP800_O2 = {0};
BSP_GPIO_IIC_T_INTERFACE Bsp_t_GpioIIC_SDP800_Out = {0};
BSP_GPIO_IIC_T_INTERFACE Bsp_t_GpioIIC_Bmp280 = {0};
BSP_GPIO_IIC_T_INTERFACE Bsp_t_GpioIIC_Bq4050 = {0};
BSP_GPIO_IIC_T_INTERFACE Bsp_t_GpioIIC_Ds1339 = {0};
BSP_GPIO_IIC_T_INTERFACE Bsp_t_GpioIIC_SpO2 = {0};
/// 数据结构实体---按键
BSP_KEY_T_INTERFACE Bsp_t_Key1 = {0};
BSP_KEY_T_INTERFACE Bsp_t_Key2 = {0};
/// 数据结构实体---LED
BSP_LED_T_INTERFACE Bsp_t_Led1 = {0};
BSP_LED_T_INTERFACE Bsp_t_Led2 = {0};
BSP_LED_T_INTERFACE Bsp_t_Led3 = {0};
BSP_LED_T_INTERFACE Bsp_t_Led4 = {0};
BSP_LED_T_INTERFACE Bsp_t_Led5 = {0};
BSP_LED_T_INTERFACE Bsp_t_Led6 = {0};
/// 数据结构实体---高压氧压力传感器
BSP_ABPDANN150PGAA5_T_INTERFACE Bsp_t_ABPDANN150PGAA5 = {0};
/// 数据结构实体---CPU
BSP_CPU_T_INTERFACE Bsp_t_Cpu;
/// 数据结构实体---气路氧浓度传感器
BSP_OCS3FA_T_INTERFACE Bsp_t_Ocs3fa_Pipe = {0};
/// 数据结构实体---环境氧浓度传感器
BSP_OCS3FA_T_INTERFACE Bsp_t_Ocs3fa_Environment = {0};
/// 数据结构实体---EEPROM
BSP_EEPROM_T_INTERFACE Bsp_t_Eeprom = {0};
/// 数据结构实体---出口压差传感器
BSP_SDP500_T_INTERFACE Bsp_t_Sdp800_Out = {0};
/// 数据结构实体---氧气气路压差传感器
BSP_SDP500_T_INTERFACE Bsp_t_Sdp800_O2 = {0};
/// 数据结构实体---流量传感器(仅作为校准工装使用)
BSP_SFM3000_T_INTERFACE Bsp_t_SFM3000 = {0};
/// 数据结构实体---报警CPU
BSP_ALARM_T_INTERFACE Bsp_t_AlarmCPU;
/// 数据结构实体---环境温度与气压传感器
BSP_BMP280_T_INTERFACE Bsp_t_Bsp280 = {0};
/// 数据结构实体---电池管理芯片
BSP_BQ4050_T_INTERFACE Bsp_t_Bq4050 = {0};
/// 数据结构实体---RTC时钟芯片
BSP_DS1339_T_INTERFACE Bsp_t_Ds1339 = {0};
/// 数据结构实体---风机
BSP_AIRFAN_T_INTERFACE Bsp_t_AirFan = {0};
/// 数据结构实体---血氧
BSP_SPO2_T_INTERFACE Bsp_SpO2_s_Data = {0};
/// 数据结构实体---比例阀
BSP_PROPORTIONAL_VALVES_T_INTERFACE Bsp_t_ProportionalValves;
/// 数据结构实体---呼末二氧化碳
BSP_ETCO2_T_INTERFACE Bsp_EtCO2_s;
/// 数据结构实体---风扇
BSP_FAN_T_INTERFACE Bsp_t_Fan = {0};
/// 数据结构实体---雾化阀
BSP_NEBULIZER_T_INTERFACE Bsp_t_Nebulizer = {0};
/// 数据结构实体---锂电池充电芯片LTC4015
BSP_LTC4015_T_INTERFACE Bsp_t_Ltc4015Interface = {0};
/// 数据结构实体---出口端管路压力传感器MPXV4006GC6U
BSP_MPXV4006GC6U_T_INTERFACE Bsp_t_MPXV4006GC6U_Out;
/// 数据结构实体---面罩端管路压力传感器MPXV4006GC6U
BSP_MPXV4006GC6U_T_INTERFACE Bsp_t_MPXV4006GC6U_Mask;
/// 数据结构实体---面罩端管路压力传感器MPXV4006GC6U
BSP_MPXV70XXGC6U_T_INTERFACE Bsp_t_MPXV70xxGC6U;
/// 数据结构实体---调试接口
APP_DEBUG_T_INTERFACE Bsp_t_AppDebug;
MODULE_DEBUG_T_INTERFACE Bsp_t_ModuleDebug;
/// 数据结构实体---单元测试接口
MODULE_UNITY_T_INTERFACE Bsp_t_ModuleUnity;
// TODO:不允许使用extern
extern RTC_HandleTypeDef hrtc;
/* 私有函数声明 (Private function prototypes)----------------------------------*/
static void Bsp_Ocs3fa_Pipe_TxFun(int8_t *_ucp_txBuf, uint16_t _us_txLen);
static void Bsp_Ocs3fa_Internal_TxFun(int8_t *_ucp_txBuf, uint16_t _us_txLen);
static void Bsp_AlarmCPU_TxFun(uint8_t *_ucp_txBuf, uint16_t _us_txLen);
static void Bsp_AirFan_On(uint8_t OnOff);
static void Bsp_AirFan_Da(uint16_t _us_da);
static void Bsp_Adc_Cycle_100ms(void);
// static void Bsp_Adc_Cycle_100ms(void);
static void Bsp_LedDebugCycle_1000ms(void);
/* 私有函数实体 (Private functions)--------------------------------------------*/
static void Bsp_OsDelay_ms(uint16_t _us_time_ms)
{
    MODULE_OS_DELAY_MS(_us_time_ms);
}
static void Bsp_SeggerRtt_WriteStr(uint8_t *_ucp_buf, uint16_t _us_len)
{
    // RTT
    SEGGER_RTT_Write(0, (uint8_t *)_ucp_buf, _us_len);
    MODULE_OS_DELAY_MS(_us_len / 16);
    // UART
    if (AppBipapInterface_t_SetPara.LcdDebug_OnOff_EtCO2_To_Debug == 1)
    {
        Bsp_t_Uart1.t_Output.fnp_TxBuf(&Bsp_t_Uart1, _ucp_buf, _us_len);
        MODULE_OS_DELAY_MS(_us_len);
    }
}
static uint8_t Bsp_SeggerRtt_NoBlockingRead(uint8_t *_ucp_buf, uint8_t _us_bufSize)
{
    return SEGGER_RTT_Read(0, _ucp_buf, _us_bufSize);
}
static void Bsp_DebugOutStr(int8_t *_cp_str)
{
    Bsp_t_ModuleDebug.t_Output.fnp_DebugOutStr(&Bsp_t_ModuleDebug, (char *)_cp_str);
}
static void Bsp_DebugOutHex(int8_t *_cp_Name, uint8_t *_cp_buf, uint16_t _us_len)
{
    Bsp_t_ModuleDebug.t_Output.fnp_DebugOutHex(&Bsp_t_ModuleDebug, (char *)_cp_Name, _cp_buf, _us_len);
}
static uint8_t Bsp_DebugInputNum(uint16_t *Number, uint8_t MaxDight)
{
    return Bsp_t_ModuleDebug.t_Output.fnp_DebugInputNum(&Bsp_t_ModuleDebug, Number, MaxDight);
}
/**
 * @brief 封装管路氧浓度传感器发送函数
 * @param[in]  _ucp_txBuf   数据地址
 * @param[in]  _us_txLen    数据长度
 */
static void Bsp_Ocs3fa_Pipe_TxFun(int8_t *_ucp_txBuf, uint16_t _us_txLen)
{
    Bsp_t_Uart8.t_Output.fnp_TxBuf(&Bsp_t_Uart8, (uint8_t *)_ucp_txBuf, _us_txLen);
}
/**
 * @brief 封装环境氧浓度传感器发送函数
 * @param[in]  _ucp_txBuf   数据地址
 * @param[in]  _us_txLen    数据长度
 */
static void Bsp_Ocs3fa_Internal_TxFun(int8_t *_ucp_txBuf, uint16_t _us_txLen)
{
    Bsp_t_Uart6.t_Output.fnp_TxBuf(&Bsp_t_Uart6, (uint8_t *)_ucp_txBuf, _us_txLen);
}
/**
 * @brief 封装报警CPU发送函数
 * @param[in]  _ucp_txBuf   数据地址
 * @param[in]  _us_txLen    数据长度
 */
static void Bsp_AlarmCPU_TxFun(uint8_t *_ucp_txBuf, uint16_t _us_txLen)
{
    // Bsp_t_Uart7.t_Output.fnp_TxBuf(&Bsp_t_Uart7, (uint8_t *)_ucp_txBuf, _us_txLen);
}

/**
 * @brief
 * @param[in]  OnOff        My Param doc
 */
static void Bsp_AirFan_On(uint8_t OnOff)
{
    if (OnOff == true)
    {
        HAL_GPIO_WritePin(GPIO_AIRFAN_BRAKE_GPIO_Port, GPIO_AIRFAN_BRAKE_Pin, GPIO_PIN_SET);
        Bsp_t_AirFan.t_Output.uc_Read_Brake = 1;
    }
    else
    {
        HAL_GPIO_WritePin(GPIO_AIRFAN_BRAKE_GPIO_Port, GPIO_AIRFAN_BRAKE_Pin, GPIO_PIN_RESET);
        Bsp_t_AirFan.t_Output.uc_Read_Brake = 0;
    }
}

/**
 * @brief
 * @param[in]  OnOff        My Param doc
 */
static void Bsp_AirFan_Da(uint16_t _us_da)
{
    BspDac_Write_Da(2, _us_da);
    Bsp_t_AirFan.t_Output.us_Read_Da = _us_da;
}
/**
 * @brief
 * @return uint16_t
 */
static uint16_t Bsp_AirFan_GetTimCmt(void)
{
    return __HAL_TIM_GET_COUNTER(BSP_AIRFAN_FREQ_TIMX);
}
/**
 * @brief
 * @param[in]  _us_setValue My Param doc
 */
static void Bsp_AirFan_SetTimCmt(uint16_t _us_setValue)
{
    __HAL_TIM_SET_COUNTER(BSP_AIRFAN_FREQ_TIMX, _us_setValue);
}
/**
 * @brief
 */
static void Bsp_AirFan_DebugOnCallback(void)
{
    AppBipapInterface_t_Para.Flag_Setting = 1;
}
/**
 * @brief
 */
static void Bsp_AirFan_DebugOffCallback(void)
{
    AppBipapInterface_t_Para.Flag_Setting = 0;
}
/**
 * @brief   周期执行函数
 * @note    用于Debug测试等
 * @param   None
 * @return  None
 */
static void Bsp_Adc_Cycle_100ms(void)
{
    uint8_t *pbuf;
    uint16_t i16, j16;
    int16_t n16;
    int32_t s32;
    static uint8_t si = 0;
    //
    // if(BspAdc_DebugTest_Enable==1)
    {
        si++;
        if (si >= 10)
        {
            si = 0;
            BspAdc_Update();
            //
            pbuf = ModuleMemManager_Get(E_MEM_MANAGER_TYPE_256B);
            //----------ADC1
            for (pbuf[250] = pbuf[251] = pbuf[252] = 0;
                 pbuf[250] < BSP_ADC1_DMA_CHANNEL_MAX; pbuf[250]++)
            {
                //
                pbuf[252] = sprintf((char *)&pbuf[pbuf[251]], "AD1-%02d:%05d",
                                    pbuf[250] + 1, BspAdc1_DmaBuf[pbuf[250]]);
                pbuf[251] += pbuf[252];
                //
                pbuf[252] = sprintf((char *)&pbuf[pbuf[251]], "(%04d mV)",
                                    BSP_ADC_CONVERT_TO_MV(BspAdc1_DmaBuf[pbuf[250]]));
                pbuf[251] += pbuf[252];
                //
                if (pbuf[250] == BSP_ADC_PRESS_O2)
                {
                    Bsp_t_ABPDANN150PGAA5.t_Input.us_SensorOutputVoltage_mV = BSP_ABPDANN150PGAA5_ADC_TO_MV(BspAdc1_DmaBuf[pbuf[250]]);
                    Bsp_t_ABPDANN150PGAA5.t_Output.fnp_Read(&Bsp_t_ABPDANN150PGAA5);
                    pbuf[252] = sprintf((char *)&pbuf[pbuf[251]],
                                        "(Press O2  :%04lu Pa)\r\n", Bsp_t_ABPDANN150PGAA5.t_Output.ul_PressValue_pa);
                    pbuf[251] += pbuf[252];
                }
                else if (pbuf[250] == BSP_ADC_PRESS_OUT)
                {
                    Bsp_t_MPXV4006GC6U_Out.t_Output.fnp_DataConvert(BspAdc1_DmaBuf[pbuf[250]],
                                                                    AppBipapInterface_t_SetPara.ManufacturerCalibration_Sensor_PressOut_Zero,
                                                                    AppBipapInterface_t_SetPara.ManufacturerCalibration_Sensor_PressOut_50cmH2O_Offset,
                                                                    &i16, &j16);
                    pbuf[252] = sprintf((char *)&pbuf[pbuf[251]],
                                        "(Press Out :%04d Pa,%d.%d cmH2O)\r\n", i16,
                                        j16 / 1000, j16 % 1000);
                    pbuf[251] += pbuf[252];
                }
                else if (pbuf[250] == BSP_ADC_PRESS_MASK)
                {
                    Bsp_t_MPXV4006GC6U_Mask.t_Output.fnp_DataConvert(BspAdc1_DmaBuf[pbuf[250]],
                                                                     AppBipapInterface_t_SetPara.ManufacturerCalibration_Sensor_PressMask_Zero,
                                                                     AppBipapInterface_t_SetPara.ManufacturerCalibration_Sensor_PressMask_50cmH2O_Offset,
                                                                     &i16, &j16);
                    pbuf[252] = sprintf((char *)&pbuf[pbuf[251]],
                                        "(Press Mask:%04d Pa,%d.%d cmH2O)\r\n", i16,
                                        j16 / 1000, j16 % 1000);
                    pbuf[251] += pbuf[252];
                }
                else if (pbuf[250] == BSP_ADC_TEMP_AIRFAN)
                {
                    BspAirFan_Temp(&Bsp_t_AirFan, BSP_ADC_CONVERT_TO_MV(BspAdc1_DmaBuf[pbuf[250]]), &i16, &n16);
                    pbuf[252] = sprintf((char *)&pbuf[pbuf[251]],
                                        "(TempAirfan:%d Ohm,%d C,err=%d)\r\n", i16, n16, Bsp_t_AirFan.t_Output.uc_TempError);
                    pbuf[251] += pbuf[252];
                }
                else if (pbuf[250] == BSP_ADC_VOLTAGE_PCBVIN)
                {
                    pbuf[252] = sprintf(
                        (char *)&pbuf[pbuf[251]], "(Voltage PCBVIN:%d mV)\r\n",
                        (BspAdc1_DmaBuf[pbuf[250]] * BSP_ADC_REFERENCE_MV * 11L) / 65565);
                    pbuf[251] += pbuf[252];
                }
                else if (pbuf[250] == BSP_ADC_PRESS_ESOPHAGEAL)
                {
                    Bsp_t_MPXV70xxGC6U.t_Output.fnp_DataConvert(
                        &Bsp_t_MPXV70xxGC6U,
                        BspAdc1_DmaBuf[pbuf[250]],
                        AppBipapInterface_t_SetPara.ManufacturerCalibration_Sensor_PressEsophageal_Zero, &n16,
                        &s32);
                    pbuf[252] = sprintf((char *)&pbuf[pbuf[251]],
                                        "(Press Esophageal:%04d Pa,%d cmH2O_x1000)\r\n", n16,
                                        s32);
                    pbuf[251] += pbuf[252];
                }
                else if (pbuf[250] == BSP_ADC_VOLTAGE_ACDC)
                {
                    pbuf[252] = sprintf(
                        (char *)&pbuf[pbuf[251]], "(Voltage ACDC:%d mV)\r\n",
                        (BspAdc1_DmaBuf[pbuf[250]] * BSP_ADC_REFERENCE_MV * 11L) / 65565);
                    pbuf[251] += pbuf[252];
                }
                else if (pbuf[250] == BSP_ADC_VOLTAGE_INT)
                {
                    pbuf[252] = sprintf(
                        (char *)&pbuf[pbuf[251]], "(Voltage INT:%d mV)\r\n",
                        (BspAdc1_DmaBuf[pbuf[250]] * BSP_ADC_REFERENCE_MV * 11L) / 65565);
                    pbuf[251] += pbuf[252];
                }
                else if (pbuf[250] == BSP_ADC_VOLTAGE_BAT)
                {
                    pbuf[252] = sprintf(
                        (char *)&pbuf[pbuf[251]], "(Voltage BAT:%d mV)\r\n",
                        (BspAdc1_DmaBuf[pbuf[250]] * BSP_ADC_REFERENCE_MV * 11L) / 65565);
                    pbuf[251] += pbuf[252];
                }
                else if (pbuf[250] == BSP_ADC_VOLTAGE_SYS)
                {
                    pbuf[252] = sprintf(
                        (char *)&pbuf[pbuf[251]], "(Voltage SYS:%d mV)\r\n",
                        (BspAdc1_DmaBuf[pbuf[250]] * BSP_ADC_REFERENCE_MV * 11L) / 65565);
                    pbuf[251] += pbuf[252];
                }
                else
                {
                    pbuf[252] = sprintf((char *)&pbuf[pbuf[251]], "\r\n");
                    pbuf[251] += pbuf[252];
                }
                //
                if (BspAdc_DebugTest_Enable == 1)
                {
                    Bsp_t_ModuleDebug.t_Output.fnp_DebugOut(&Bsp_t_ModuleDebug, (char *)pbuf, strlen((char *)pbuf));
                }
                pbuf[251] = 0;
            }
            if (BspAdc_DebugTest_Enable == 1)
            {
                sprintf((char *)pbuf, "-\r\n");
                Bsp_t_ModuleDebug.t_Output.fnp_DebugOut(&Bsp_t_ModuleDebug, (char *)pbuf, strlen((char *)pbuf));
            }
            //----------ADC3
            for (pbuf[250] = pbuf[251] = pbuf[252] = 0;
                 pbuf[250] < BSP_ADC3_DMA_CHANNEL_MAX; pbuf[250]++)
            {
                //
                pbuf[252] = sprintf((char *)&pbuf[pbuf[251]], "AD3-%02d:%05d",
                                    pbuf[250] + 1, BspAdc3_DmaBuf[pbuf[250]]);
                pbuf[251] += pbuf[252];
                //
                if (pbuf[250] == BSP_AD_CPU_TEMP_CHANNEL)
                {
#ifdef STM32F407xx
                    float f_temp;
                    uint16_t i16;
                    f_temp = ((BspAdc3_DmaBuf[pbuf[250]] * ((float)BSP_ADC_REFERENCE_MV) /
                               4095000) -
                              0.76f) /
                                 0.0025f +
                             25;
                    i16 = f_temp;
                    pbuf[252] =
                        sprintf((char *)&pbuf[pbuf[251]], "(CPU-Temp:%02d)\r\n", i16);
                    pbuf[251] += pbuf[252];
#endif
#ifdef STM32H743xx
                    float f_temp;
                    uint16_t TS_CAL1;
                    uint16_t TS_CAL2;
                    static int8_t sbuf[5] = {0};
                    int8_t buf[5];
                    TS_CAL1 = *(__IO uint16_t *)(0x1FF1E820);
                    TS_CAL2 = *(__IO uint16_t *)(0x1FF1E840);
                    //
                    f_temp = (110.0f - 30.0f) * (BspAdc3_DmaBuf[pbuf[250]] * ((float)BSP_ADC_REFERENCE_MV) / 3300.0f - TS_CAL1) / (TS_CAL2 - TS_CAL1) + 30;
                    ModuleCount_Buffer_Append_s8(sbuf, sizeof(sbuf), (int8_t)f_temp);
                    memcpy(buf, sbuf, sizeof(buf));
                    ModuleCount_Sort_Buble_S8(buf, 5);
                    //
                    BspAdc_CpuTemp = buf[2];

                    pbuf[252] = sprintf((char *)&pbuf[pbuf[251]], "(CPU-Temp:%02d)\r\n",
                                        BspAdc_CpuTemp);
                    pbuf[251] += pbuf[252];
#endif
                }
                else if (pbuf[250] == BSP_AD_CPU_VREFINT_CHANNEL)
                {
                    BspAdc_Vrefint_mv = BSP_ADC_CONVERT_TO_MV(BspAdc3_DmaBuf[pbuf[250]]);
                    pbuf[252] = sprintf((char *)&pbuf[pbuf[251]], "(CPU-VREFINT:%d mV)\r\n", BspAdc_Vrefint_mv);
                    pbuf[251] += pbuf[252];
                }
                else if (pbuf[250] == BSP_AD_CPU_VBAT)
                {
                    BspAdc_Vbat_mV = 4 * BSP_ADC_CONVERT_TO_MV(BspAdc3_DmaBuf[pbuf[250]]);
                    pbuf[252] = sprintf((char *)&pbuf[pbuf[251]], "(CPU-VBAT:%d mV)\r\n", BspAdc_Vbat_mV);
                    pbuf[251] += pbuf[252];
                }
                else
                {
                    pbuf[252] = sprintf((char *)&pbuf[pbuf[251]], "(%04d mV)\r\n",
                                        BSP_ADC_CONVERT_TO_MV(BspAdc3_DmaBuf[pbuf[250]]));
                    pbuf[251] += pbuf[252];
                }
                if (BspAdc_DebugTest_Enable == 1)
                {
                    Bsp_t_ModuleDebug.t_Output.fnp_DebugOut(&Bsp_t_ModuleDebug, (char *)pbuf, strlen((char *)pbuf));
                }
                pbuf[251] = 0;
            }
            if (BspAdc_DebugTest_Enable == 1)
            {
                sprintf((char *)pbuf, "----------\r\n");
                Bsp_t_ModuleDebug.t_Output.fnp_DebugOut(&Bsp_t_ModuleDebug, (char *)pbuf, strlen((char *)pbuf));
            }
            ModuleMemManager_Free(E_MEM_MANAGER_TYPE_256B, pbuf);
        }
    }
}

static void Bsp_EtCO2_WriteGpioPower(uint8_t _highOrLow)
{
    if (_highOrLow == true)
    {
        HAL_GPIO_WritePin(GPIO_ETCO2_PWR_GPIO_Port, GPIO_ETCO2_PWR_Pin, GPIO_PIN_RESET);
    }
    else
    {
        HAL_GPIO_WritePin(GPIO_ETCO2_PWR_GPIO_Port, GPIO_ETCO2_PWR_Pin, GPIO_PIN_SET);
    }
}
static void Bsp_EtCO2_InitUart(void *_tp_interface)
{
    BSP_ETCO2_T_INTERFACE *tp_interface = _tp_interface;
    //
    if (tp_interface->t_Input.t_Module == BSP_ETCO2_E_MODULE_CAPNO)
    {
        extern UART_HandleTypeDef huart1;
        huart1.Init.BaudRate = 38400;
        huart1.Init.WordLength = UART_WORDLENGTH_9B;
        huart1.Init.StopBits = UART_STOPBITS_1;
        huart1.Init.Parity = UART_PARITY_EVEN;
        if (HAL_UART_Init(&huart1) != HAL_OK)
        {
            Error_Handler();
        }
    }
    else if (tp_interface->t_Input.t_Module == BSP_ETCO2_E_MODULE_CM2200)
    {
        extern UART_HandleTypeDef huart1;
        huart1.Init.BaudRate = 19200;
        huart1.Init.WordLength = UART_WORDLENGTH_8B;
        huart1.Init.StopBits = UART_STOPBITS_1;
        huart1.Init.Parity = UART_PARITY_NONE;
        if (HAL_UART_Init(&huart1) != HAL_OK)
        {
            Error_Handler();
        }
    }
}
static void Bsp_EtCO2_UartTx(int8_t *buf, uint16_t len)
{
    if (AppBipapInterface_t_SetPara.LcdDebug_OnOff_EtCO2_To_Debug == 0)
    {
        Bsp_t_Uart1.t_Output.fnp_TxBuf(&Bsp_t_Uart1, (uint8_t *)buf, len);
    }
}

static void Bsp_SpO2_On(uint8_t OnOff)
{
    if (OnOff == true)
    {
        HAL_GPIO_WritePin(GPIO_SPO2_PWR_GPIO_Port, GPIO_SPO2_PWR_Pin, GPIO_PIN_RESET);
    }
    else
    {
        HAL_GPIO_WritePin(GPIO_SPO2_PWR_GPIO_Port, GPIO_SPO2_PWR_Pin, GPIO_PIN_SET);
    }
}
static void Bsp_SpO2_UartTx(int8_t *buf, uint16_t len)
{
    Bsp_t_LpUart.t_Output.fnp_TxBuf(&Bsp_t_LpUart, (uint8_t *)buf, len);
}
//
static uint8_t Bsp_Fan_ReadGpioPwm(void)
{
    return HAL_GPIO_ReadPin(GPIO_FAN_PWMIN_GPIO_Port, GPIO_FAN_PWMIN_Pin);
}
static void Bsp_Fan_WriteGpioPower(uint8_t _highOrLow)
{
    if (_highOrLow == true)
    {
        HAL_GPIO_WritePin(GPIO_FAN_PWR_GPIO_Port, GPIO_FAN_PWR_Pin, GPIO_PIN_SET);
    }
    else
    {
        HAL_GPIO_WritePin(GPIO_FAN_PWR_GPIO_Port, GPIO_FAN_PWR_Pin, GPIO_PIN_RESET);
    }
}
static void Bsp_Fan_WriteGpioPwm(uint8_t _highOrLow)
{
    if (_highOrLow == true)
    {
        HAL_GPIO_WritePin(GPIO_FAN_PWMOUT_GPIO_Port, GPIO_FAN_PWMOUT_Pin, GPIO_PIN_RESET);
    }
    else
    {
        HAL_GPIO_WritePin(GPIO_FAN_PWMOUT_GPIO_Port, GPIO_FAN_PWMOUT_Pin, GPIO_PIN_SET);
    }
}
//
static void Bsp_Nebulizer_WriteGpioPower(uint8_t _highOrLow)
{
    if (_highOrLow == true)
    {
        HAL_GPIO_WritePin(GPIO_NEBULIZER_PWR_GPIO_Port, GPIO_NEBULIZER_PWR_Pin, GPIO_PIN_SET);
    }
    else
    {
        HAL_GPIO_WritePin(GPIO_NEBULIZER_PWR_GPIO_Port, GPIO_NEBULIZER_PWR_Pin, GPIO_PIN_RESET);
    }
}
//
static uint8_t Bsp_Ltc4015_ReadGpioPower(void)
{
    return HAL_GPIO_ReadPin(GPIO_LTC4015_VCC_GPIO_Port, GPIO_LTC4015_VCC_Pin);
}
static void Bsp_Ltc4015_WriteGpioPower(uint8_t _highOrLow)
{
    if (_highOrLow == true)
    {
        HAL_GPIO_WritePin(GPIO_LTC4015_VCC_GPIO_Port, GPIO_LTC4015_VCC_Pin, GPIO_PIN_SET);
    }
    else
    {
        HAL_GPIO_WritePin(GPIO_LTC4015_VCC_GPIO_Port, GPIO_LTC4015_VCC_Pin, GPIO_PIN_RESET);
    }
}
static void Bsp_Bq4050_WriteGpioPower(uint8_t _highOrLow)
{
    if (_highOrLow == true)
    {
        HAL_GPIO_WritePin(GPIO_LTC4015_VCC_GPIO_Port, GPIO_LTC4015_VCC_Pin, GPIO_PIN_SET);
    }
    else
    {
        HAL_GPIO_WritePin(GPIO_LTC4015_VCC_GPIO_Port, GPIO_LTC4015_VCC_Pin, GPIO_PIN_RESET);
    }
}
static void Bsp_Bq4050_OsDelay_ms(uint8_t _time_ms)
{
    osDelay(_time_ms);
}
//
static uint8_t Bsp_Key1_PressedCondition(void)
{
    if (GPIO_PIN_RESET == HAL_GPIO_ReadPin(BSP_KEY1_PORT, BSP_KEY1_PIN))
    {
        return true;
    }
    else
    {
        return false;
    }
}
static uint8_t Bsp_Key2_PressedCondition(void)
{
    if (GPIO_PIN_RESET == HAL_GPIO_ReadPin(BSP_KEY2_PORT, BSP_KEY2_PIN))
    {
        return true;
    }
    else
    {
        return false;
    }
}
//
static void Bsp_Led1_OnOff(uint8_t _trueOrFalse)
{
    if (_trueOrFalse == true)
    {
        HAL_GPIO_WritePin(BSP_LED_LED1_PORT, BSP_LED_LED1_PIN, GPIO_PIN_SET);
    }
    else
    {
        HAL_GPIO_WritePin(BSP_LED_LED1_PORT, BSP_LED_LED1_PIN, GPIO_PIN_RESET);
    }
}
static void Bsp_Led2_OnOff(uint8_t _trueOrFalse)
{
    if (_trueOrFalse == true)
    {
        HAL_GPIO_WritePin(BSP_LED_LED2_PORT, BSP_LED_LED2_PIN, GPIO_PIN_SET);
    }
    else
    {
        HAL_GPIO_WritePin(BSP_LED_LED2_PORT, BSP_LED_LED2_PIN, GPIO_PIN_RESET);
    }
}
static void Bsp_Led3_OnOff(uint8_t _trueOrFalse)
{
    if (_trueOrFalse == true)
    {
        HAL_GPIO_WritePin(BSP_LED_LED3_PORT, BSP_LED_LED3_PIN, GPIO_PIN_SET);
    }
    else
    {
        HAL_GPIO_WritePin(BSP_LED_LED3_PORT, BSP_LED_LED3_PIN, GPIO_PIN_RESET);
    }
}
static void Bsp_Led4_OnOff(uint8_t _trueOrFalse)
{
    if (_trueOrFalse == true)
    {
        HAL_GPIO_WritePin(BSP_LED_LED4_PORT, BSP_LED_LED4_PIN, GPIO_PIN_SET);
    }
    else
    {
        HAL_GPIO_WritePin(BSP_LED_LED4_PORT, BSP_LED_LED4_PIN, GPIO_PIN_RESET);
    }
}
static void Bsp_Led5_OnOff(uint8_t _trueOrFalse)
{
    if (_trueOrFalse == true)
    {
        HAL_GPIO_WritePin(BSP_LED_LED5_PORT, BSP_LED_LED5_PIN, GPIO_PIN_SET);
    }
    else
    {
        HAL_GPIO_WritePin(BSP_LED_LED5_PORT, BSP_LED_LED5_PIN, GPIO_PIN_RESET);
    }
}
static void Bsp_Led6_OnOff(uint8_t _trueOrFalse)
{
    if (_trueOrFalse == true)
    {
        HAL_GPIO_WritePin(BSP_LED_LED6_PORT, BSP_LED_LED6_PIN, GPIO_PIN_SET);
    }
    else
    {
        HAL_GPIO_WritePin(BSP_LED_LED6_PORT, BSP_LED_LED6_PIN, GPIO_PIN_RESET);
    }
}
//
static void Bsp_GpioIIC_WriteGpio_Eeprom(BSP_GPIO_IIC_E_PIN _e_pin, uint8_t _trueOrFalse)
{
    if (_e_pin == BSP_GPIO_IIC_E_PIN_SCL)
    {
        if ((_trueOrFalse == true))
        {
            HAL_GPIO_WritePin(GPIO_EEPROM_SCL_GPIO_Port, GPIO_EEPROM_SCL_Pin, GPIO_PIN_SET);
        }
        else
        {
            HAL_GPIO_WritePin(GPIO_EEPROM_SCL_GPIO_Port, GPIO_EEPROM_SCL_Pin, GPIO_PIN_RESET);
        }
    }
    else if (_e_pin == BSP_GPIO_IIC_E_PIN_SDA)
    {
        if ((_trueOrFalse == true))
        {
            HAL_GPIO_WritePin(GPIO_EEPROM_SDA_GPIO_Port, GPIO_EEPROM_SDA_Pin, GPIO_PIN_SET);
        }
        else
        {
            HAL_GPIO_WritePin(GPIO_EEPROM_SDA_GPIO_Port, GPIO_EEPROM_SDA_Pin, GPIO_PIN_RESET);
        }
    }
}
static uint8_t Bsp_GpioIIC_ReadGpio_Eeprom(BSP_GPIO_IIC_E_PIN _e_pin)
{
    if (_e_pin == BSP_GPIO_IIC_E_PIN_SCL)
    {
        return HAL_GPIO_ReadPin(GPIO_EEPROM_SCL_GPIO_Port, GPIO_EEPROM_SCL_Pin);
    }
    else if (_e_pin == BSP_GPIO_IIC_E_PIN_SDA)
    {
        return HAL_GPIO_ReadPin(GPIO_EEPROM_SDA_GPIO_Port, GPIO_EEPROM_SDA_Pin);
    }
    else
    {
        return false;
    }
}
static void Bsp_GpioIIC_WriteGpio_SDP800_O2(BSP_GPIO_IIC_E_PIN _e_pin, uint8_t _trueOrFalse)
{
    if (_e_pin == BSP_GPIO_IIC_E_PIN_SCL)
    {
        if ((_trueOrFalse == true))
        {
            HAL_GPIO_WritePin(GPIO_O2_SDP800_SCL_GPIO_Port, GPIO_O2_SDP800_SCL_Pin, GPIO_PIN_SET);
        }
        else
        {
            HAL_GPIO_WritePin(GPIO_O2_SDP800_SCL_GPIO_Port, GPIO_O2_SDP800_SCL_Pin, GPIO_PIN_RESET);
        }
    }
    else if (_e_pin == BSP_GPIO_IIC_E_PIN_SDA)
    {
        if ((_trueOrFalse == true))
        {
            HAL_GPIO_WritePin(GPIO_O2_SDP800_SDA_GPIO_Port, GPIO_O2_SDP800_SDA_Pin, GPIO_PIN_SET);
        }
        else
        {
            HAL_GPIO_WritePin(GPIO_O2_SDP800_SDA_GPIO_Port, GPIO_O2_SDP800_SDA_Pin, GPIO_PIN_RESET);
        }
    }
}
static uint8_t Bsp_GpioIIC_ReadGpio_SDP800_O2(BSP_GPIO_IIC_E_PIN _e_pin)
{
    if (_e_pin == BSP_GPIO_IIC_E_PIN_SCL)
    {
        return HAL_GPIO_ReadPin(GPIO_O2_SDP800_SCL_GPIO_Port, GPIO_O2_SDP800_SCL_Pin);
    }
    else if (_e_pin == BSP_GPIO_IIC_E_PIN_SDA)
    {
        return HAL_GPIO_ReadPin(GPIO_O2_SDP800_SDA_GPIO_Port, GPIO_O2_SDP800_SDA_Pin);
    }
    else
    {
        return false;
    }
}
static void Bsp_GpioIIC_WriteGpio_SDP800_Out(BSP_GPIO_IIC_E_PIN _e_pin, uint8_t _trueOrFalse)
{
    if (_e_pin == BSP_GPIO_IIC_E_PIN_SCL)
    {
        if ((_trueOrFalse == true))
        {
            HAL_GPIO_WritePin(GPIO_SDP500_SCL_GPIO_Port, GPIO_SDP500_SCL_Pin, GPIO_PIN_SET);
        }
        else
        {
            HAL_GPIO_WritePin(GPIO_SDP500_SCL_GPIO_Port, GPIO_SDP500_SCL_Pin, GPIO_PIN_RESET);
        }
    }
    else if (_e_pin == BSP_GPIO_IIC_E_PIN_SDA)
    {
        if ((_trueOrFalse == true))
        {
            HAL_GPIO_WritePin(GPIO_SDP500_SDA_GPIO_Port, GPIO_SDP500_SDA_Pin, GPIO_PIN_SET);
        }
        else
        {
            HAL_GPIO_WritePin(GPIO_SDP500_SDA_GPIO_Port, GPIO_SDP500_SDA_Pin, GPIO_PIN_RESET);
        }
    }
}
static uint8_t Bsp_GpioIIC_ReadGpio_SDP800_Out(BSP_GPIO_IIC_E_PIN _e_pin)
{
    if (_e_pin == BSP_GPIO_IIC_E_PIN_SCL)
    {
        return HAL_GPIO_ReadPin(GPIO_SDP500_SCL_GPIO_Port, GPIO_SDP500_SCL_Pin);
    }
    else if (_e_pin == BSP_GPIO_IIC_E_PIN_SDA)
    {
        return HAL_GPIO_ReadPin(GPIO_SDP500_SDA_GPIO_Port, GPIO_SDP500_SDA_Pin);
    }
    else
    {
        return false;
    }
}
static void Bsp_GpioIIC_WriteGpio_Bmp280(BSP_GPIO_IIC_E_PIN _e_pin, uint8_t _trueOrFalse)
{
    if (_e_pin == BSP_GPIO_IIC_E_PIN_SCL)
    {
        if ((_trueOrFalse == true))
        {
            HAL_GPIO_WritePin(GPIO_BMP280_SCL_GPIO_Port, GPIO_BMP280_SCL_Pin, GPIO_PIN_SET);
        }
        else
        {
            HAL_GPIO_WritePin(GPIO_BMP280_SCL_GPIO_Port, GPIO_BMP280_SCL_Pin, GPIO_PIN_RESET);
        }
    }
    else if (_e_pin == BSP_GPIO_IIC_E_PIN_SDA)
    {
        if ((_trueOrFalse == true))
        {
            HAL_GPIO_WritePin(GPIO_BMP280_SDA_GPIO_Port, GPIO_BMP280_SDA_Pin, GPIO_PIN_SET);
        }
        else
        {
            HAL_GPIO_WritePin(GPIO_BMP280_SDA_GPIO_Port, GPIO_BMP280_SDA_Pin, GPIO_PIN_RESET);
        }
    }
}
static uint8_t Bsp_GpioIIC_ReadGpio_Bmp280(BSP_GPIO_IIC_E_PIN _e_pin)
{
    if (_e_pin == BSP_GPIO_IIC_E_PIN_SCL)
    {
        return HAL_GPIO_ReadPin(GPIO_BMP280_SCL_GPIO_Port, GPIO_BMP280_SCL_Pin);
    }
    else if (_e_pin == BSP_GPIO_IIC_E_PIN_SDA)
    {
        return HAL_GPIO_ReadPin(GPIO_BMP280_SDA_GPIO_Port, GPIO_BMP280_SDA_Pin);
    }
    else
    {
        return false;
    }
}
static void Bsp_GpioIIC_WriteGpio_Bq4050(BSP_GPIO_IIC_E_PIN _e_pin, uint8_t _trueOrFalse)
{
    if (_e_pin == BSP_GPIO_IIC_E_PIN_SCL)
    {
        if ((_trueOrFalse == true))
        {
            HAL_GPIO_WritePin(GPIO_LTC4015_SCL_GPIO_Port, GPIO_LTC4015_SCL_Pin, GPIO_PIN_SET);
        }
        else
        {
            HAL_GPIO_WritePin(GPIO_LTC4015_SCL_GPIO_Port, GPIO_LTC4015_SCL_Pin, GPIO_PIN_RESET);
        }
    }
    else if (_e_pin == BSP_GPIO_IIC_E_PIN_SDA)
    {
        if ((_trueOrFalse == true))
        {
            HAL_GPIO_WritePin(GPIO_LTC4015_SDA_GPIO_Port, GPIO_LTC4015_SDA_Pin, GPIO_PIN_SET);
        }
        else
        {
            HAL_GPIO_WritePin(GPIO_LTC4015_SDA_GPIO_Port, GPIO_LTC4015_SDA_Pin, GPIO_PIN_RESET);
        }
    }
}
static uint8_t Bsp_GpioIIC_ReadGpio_Bq4050(BSP_GPIO_IIC_E_PIN _e_pin)
{
    if (_e_pin == BSP_GPIO_IIC_E_PIN_SCL)
    {
        return HAL_GPIO_ReadPin(GPIO_LTC4015_SCL_GPIO_Port, GPIO_LTC4015_SCL_Pin);
    }
    else if (_e_pin == BSP_GPIO_IIC_E_PIN_SDA)
    {
        return HAL_GPIO_ReadPin(GPIO_LTC4015_SDA_GPIO_Port, GPIO_LTC4015_SDA_Pin);
    }
    else
    {
        return false;
    }
}
static void Bsp_GpioIIC_WriteGpio_Ds1339(BSP_GPIO_IIC_E_PIN _e_pin, uint8_t _trueOrFalse)
{
    if (_e_pin == BSP_GPIO_IIC_E_PIN_SCL)
    {
        if ((_trueOrFalse == true))
        {
            HAL_GPIO_WritePin(GPIO_DS1339_SCL_GPIO_Port, GPIO_DS1339_SCL_Pin, GPIO_PIN_SET);
        }
        else
        {
            HAL_GPIO_WritePin(GPIO_DS1339_SCL_GPIO_Port, GPIO_DS1339_SCL_Pin, GPIO_PIN_RESET);
        }
    }
    else if (_e_pin == BSP_GPIO_IIC_E_PIN_SDA)
    {
        if ((_trueOrFalse == true))
        {
            HAL_GPIO_WritePin(GPIO_DS1339_SDA_GPIO_Port, GPIO_DS1339_SDA_Pin, GPIO_PIN_SET);
        }
        else
        {
            HAL_GPIO_WritePin(GPIO_DS1339_SDA_GPIO_Port, GPIO_DS1339_SDA_Pin, GPIO_PIN_RESET);
        }
    }
}
static uint8_t Bsp_GpioIIC_ReadGpio_Ds1339(BSP_GPIO_IIC_E_PIN _e_pin)
{
    if (_e_pin == BSP_GPIO_IIC_E_PIN_SCL)
    {
        return HAL_GPIO_ReadPin(GPIO_DS1339_SCL_GPIO_Port, GPIO_DS1339_SCL_Pin);
    }
    else if (_e_pin == BSP_GPIO_IIC_E_PIN_SDA)
    {
        return HAL_GPIO_ReadPin(GPIO_DS1339_SDA_GPIO_Port, GPIO_DS1339_SDA_Pin);
    }
    else
    {
        return false;
    }
}
static void Bsp_GpioIIC_WriteGpio_SpO2(BSP_GPIO_IIC_E_PIN _e_pin, uint8_t _trueOrFalse)
{
    if (_e_pin == BSP_GPIO_IIC_E_PIN_SCL)
    {
        if ((_trueOrFalse == true))
        {
            HAL_GPIO_WritePin(GPIO_LPUART_TX_SPO2_GPIO_Port, GPIO_LPUART_TX_SPO2_Pin, GPIO_PIN_SET);
        }
        else
        {
            HAL_GPIO_WritePin(GPIO_LPUART_TX_SPO2_GPIO_Port, GPIO_LPUART_TX_SPO2_Pin, GPIO_PIN_RESET);
        }
    }
    else if (_e_pin == BSP_GPIO_IIC_E_PIN_SDA)
    {
        if ((_trueOrFalse == true))
        {
            HAL_GPIO_WritePin(GPIO_LPUART_RX_SPO2_GPIO_Port, GPIO_LPUART_RX_SPO2_Pin, GPIO_PIN_SET);
        }
        else
        {
            HAL_GPIO_WritePin(GPIO_LPUART_RX_SPO2_GPIO_Port, GPIO_LPUART_RX_SPO2_Pin, GPIO_PIN_RESET);
        }
    }
}
static uint8_t Bsp_GpioIIC_ReadGpio_SpO2(BSP_GPIO_IIC_E_PIN _e_pin)
{
    if (_e_pin == BSP_GPIO_IIC_E_PIN_SCL)
    {
        return HAL_GPIO_ReadPin(GPIO_LPUART_TX_SPO2_GPIO_Port, GPIO_LPUART_TX_SPO2_Pin);
    }
    else if (_e_pin == BSP_GPIO_IIC_E_PIN_SDA)
    {
        return HAL_GPIO_ReadPin(GPIO_LPUART_RX_SPO2_GPIO_Port, GPIO_LPUART_RX_SPO2_Pin);
    }
    else
    {
        return false;
    }
}
static void Bsp_GpioIIC_GpioInit_SFM3000(void)
{
    GPIO_InitTypeDef GPIO_InitStruct = {0};

    GPIO_InitStruct.Pin = GPIO_LPUART_RX_SPO2_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(GPIO_LPUART_RX_SPO2_GPIO_Port, &GPIO_InitStruct);
    GPIO_InitStruct.Pin = GPIO_LPUART_TX_SPO2_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(GPIO_LPUART_TX_SPO2_GPIO_Port, &GPIO_InitStruct);
}
/// UART
static void Bsp_Lpuart1_Parse(uint8_t *_ucp_buf, uint16_t _us_len)
{
    Bsp_SpO2_s_Data.t_Transplant.fnp_RxParse(&Bsp_SpO2_s_Data, _ucp_buf, _us_len);
}
static void Bsp_uart1_Parse(uint8_t *_ucp_buf, uint16_t _us_len)
{
    if (AppBipapInterface_t_SetPara.LcdDebug_OnOff_EtCO2_To_Debug == 1)
    {
        Bsp_t_ModuleDebug.t_Transplant.fnp_InterruptRx(&Bsp_t_ModuleDebug, _ucp_buf, _us_len);
    }
    else
    {
        Bsp_EtCO2_s.t_Transplant.fnp_RxParse(&Bsp_EtCO2_s, _ucp_buf, _us_len);
    }
}
static void Bsp_uart3_Parse(uint8_t *_ucp_buf, uint16_t _us_len)
{
    ModuleProtocol_Decode(_ucp_buf, _us_len, &TaskHci_t_ProtocolAssembleData, TaskHci_Uart_Tx, ModuleProtocol_Handle, NULL);
}
static void Bsp_uart6_Parse(uint8_t *_ucp_buf, uint16_t _us_len)
{
    Bsp_t_Ocs3fa_Environment.t_Transplant.fnp_RxParse(&Bsp_t_Ocs3fa_Environment, _ucp_buf, _us_len);
}
static void Bsp_uart8_Parse(uint8_t *_ucp_buf, uint16_t _us_len)
{
    Bsp_t_Ocs3fa_Pipe.t_Transplant.fnp_RxParse(&Bsp_t_Ocs3fa_Pipe, _ucp_buf, _us_len);
}
/* 公有函数实体 (Public functions)---------------------------------------------*/
/**
 * @brief
 */
void BspAdc_Update(void)
{
#ifdef STM32H743xx
    SCB_InvalidateDCache_by_Addr((uint32_t *)BspAdc1_DmaBuf,
                                 sizeof(BspAdc1_DmaBuf));
    SCB_InvalidateDCache_by_Addr((uint32_t *)BspAdc3_DmaBuf,
                                 sizeof(BspAdc3_DmaBuf));
#endif
}
/**
 * @brief 初始化函数
 */
void Bsp_Init(void)
{
    // Boot版本载入
    if (ucp_BootVerStr[0] == 'V')
    {
        memcpy(Bsp_BootVerStr, ucp_BootVerStr, 11);
    }
    else
    {
        memcpy(Bsp_BootVerStr, "V000_000000", 11);
    }
    // Bug：（不好使）复位源识别
    Bsp_Pwr_ResetFlag = (BSP_PWR_E_RESET_FLAG)(*ucp_BootResetFlag);
    if (Bsp_Pwr_ResetFlag == BSP_PWR_E_RESET_FLAG_PORRST)
    {
        // 冷启动处理
        us_ResetCmt_SFR = 0;
        us_ResetCmt_IWDG = 0;
        us_ResetCmt_PIN = 0;
        us_ResetCmt_LPWR = 0;
        us_ResetCmt_BOR = 0;
        BSP_BKPRAM_WRITE(BSP_BKPRAM_RST_SFT_CMT, 0);
        BSP_BKPRAM_WRITE(BSP_BKPRAM_RST_IWDG_CMT, 0);
        BSP_BKPRAM_WRITE(BSP_BKPRAM_RST_PIN_CMT, 0);
        BSP_BKPRAM_WRITE(BSP_BKPRAM_RST_LPWR_CMT, 0);
        BSP_BKPRAM_WRITE(BSP_BKPRAM_RST_BOR_CMT, 0);
    }
    else
    {
        us_ResetCmt_SFR = BSP_BKPRAM_READ(BSP_BKPRAM_RST_SFT_CMT);
        us_ResetCmt_IWDG = BSP_BKPRAM_READ(BSP_BKPRAM_RST_IWDG_CMT);
        us_ResetCmt_PIN = BSP_BKPRAM_READ(BSP_BKPRAM_RST_PIN_CMT);
        us_ResetCmt_LPWR = BSP_BKPRAM_READ(BSP_BKPRAM_RST_LPWR_CMT);
        us_ResetCmt_BOR = BSP_BKPRAM_READ(BSP_BKPRAM_RST_BOR_CMT);
        if (Bsp_Pwr_ResetFlag == BSP_PWR_E_RESET_FLAG_SFTRST)
        {
            // 软复位处理
            us_ResetCmt_SFR++;
            BSP_BKPRAM_WRITE(BSP_BKPRAM_RST_SFT_CMT, us_ResetCmt_SFR);
        }
        else if (Bsp_Pwr_ResetFlag == BSP_PWR_E_RESET_FLAG_IWDGRST)
        {
            // 独立看门狗复位处理
            us_ResetCmt_IWDG++;
            BSP_BKPRAM_WRITE(BSP_BKPRAM_RST_IWDG_CMT, us_ResetCmt_IWDG);
        }
        else if (Bsp_Pwr_ResetFlag == BSP_PWR_E_RESET_FLAG_PINRST)
        {
            // 引脚复位
            us_ResetCmt_PIN++;
            BSP_BKPRAM_WRITE(BSP_BKPRAM_RST_PIN_CMT, us_ResetCmt_PIN);
        }
        else if (Bsp_Pwr_ResetFlag == BSP_PWR_E_RESET_FLAG_LPWRRST)
        {
            //
            us_ResetCmt_LPWR++;
            BSP_BKPRAM_WRITE(BSP_BKPRAM_RST_LPWR_CMT, us_ResetCmt_LPWR);
        }
        else if (Bsp_Pwr_ResetFlag == BSP_PWR_E_RESET_FLAG_BORRST)
        {
            //
            us_ResetCmt_BOR++;
            BSP_BKPRAM_WRITE(BSP_BKPRAM_RST_BOR_CMT, us_ResetCmt_BOR);
        }
    }
    //
    memset((char *)BspAdc1_DmaBuf, 0, sizeof(BspAdc1_DmaBuf));
    memset((char *)BspAdc3_DmaBuf, 0, sizeof(BspAdc3_DmaBuf));
    // 预先初始化Debug（仅部分初始化）
    memset((char *)&Bsp_t_ModuleDebug, 0, sizeof(Bsp_t_ModuleDebug));
    ModuleDebug_Init(&Bsp_t_ModuleDebug);
    //
    Module_Memory_Init();
    // 数据观察点
    memset((char *)&Bsp_t_Dwt, 0, sizeof(Bsp_t_Dwt));
    BspDwt_Init(&Bsp_t_Dwt);
    //
    memset((char *)&Bsp_t_LpUart, 0, sizeof(BSP_UART_T_INTERFACE));
    Bsp_t_LpUart.t_Input.e_Channel = BSP_UART_CH_LPUART1;
    Bsp_t_LpUart.t_Input.ucp_TxBuf = LpUart_Tx1Buf;
    Bsp_t_LpUart.t_Input.us_TxBufSize = BSP_LPUART_1_TXBUF_SIZE;
    Bsp_t_LpUart.t_Input.ucp_RxBuf = LpUart_Rx1Buf;
    Bsp_t_LpUart.t_Input.us_RxBufSize = BSP_LPUART_1_RXBUF_SIZE;
    Bsp_t_LpUart.t_Input.tp_UartHandle = &hlpuart1;
    Bsp_t_LpUart.t_Input.tp_DmaTxHandel = &hdma_lpuart1_tx;
    Bsp_t_LpUart.t_Input.tp_DmaRxHandel = &hdma_lpuart1_rx;
    Bsp_t_LpUart.t_Input.fnp_RxParse = Bsp_Lpuart1_Parse;
    BspUart_Init(&Bsp_t_LpUart);
    //
    memset((char *)&Bsp_t_Uart1, 0, sizeof(BSP_UART_T_INTERFACE));
    Bsp_t_Uart1.t_Input.e_Channel = BSP_UART_CH_UART1;
    Bsp_t_Uart1.t_Input.ucp_TxBuf = Uart_Tx1Buf;
    Bsp_t_Uart1.t_Input.us_TxBufSize = BSP_UART_1_TXBUF_SIZE;
    Bsp_t_Uart1.t_Input.ucp_RxBuf = Uart_Rx1Buf;
    Bsp_t_Uart1.t_Input.us_RxBufSize = BSP_UART_1_RXBUF_SIZE;
    Bsp_t_Uart1.t_Input.tp_UartHandle = &huart1;
    Bsp_t_Uart1.t_Input.tp_DmaTxHandel = &hdma_usart1_tx;
    Bsp_t_Uart1.t_Input.tp_DmaRxHandel = &hdma_usart1_rx;
    Bsp_t_Uart1.t_Input.fnp_RxParse = Bsp_uart1_Parse;
    BspUart_Init(&Bsp_t_Uart1);
    //
    memset((char *)&Bsp_t_Uart3, 0, sizeof(BSP_UART_T_INTERFACE));
    Bsp_t_Uart3.t_Input.e_Channel = BSP_UART_CH_UART3;
    Bsp_t_Uart3.t_Input.ucp_TxBuf = Uart_Tx3Buf;
    Bsp_t_Uart3.t_Input.us_TxBufSize = BSP_UART_3_TXBUF_SIZE;
    Bsp_t_Uart3.t_Input.ucp_RxBuf = Uart_Rx3Buf;
    Bsp_t_Uart3.t_Input.us_RxBufSize = BSP_UART_3_RXBUF_SIZE;
    Bsp_t_Uart3.t_Input.tp_UartHandle = &huart3;
    Bsp_t_Uart3.t_Input.tp_DmaTxHandel = &hdma_usart3_tx;
    Bsp_t_Uart3.t_Input.tp_DmaRxHandel = &hdma_usart3_rx;
    Bsp_t_Uart3.t_Input.fnp_RxParse = Bsp_uart3_Parse;
    BspUart_Init(&Bsp_t_Uart3);
    //
    memset((char *)&Bsp_t_Uart6, 0, sizeof(BSP_UART_T_INTERFACE));
    Bsp_t_Uart6.t_Input.e_Channel = BSP_UART_CH_UART6;
    Bsp_t_Uart6.t_Input.ucp_TxBuf = Uart_Tx6Buf;
    Bsp_t_Uart6.t_Input.us_TxBufSize = BSP_UART_6_TXBUF_SIZE;
    Bsp_t_Uart6.t_Input.ucp_RxBuf = Uart_Rx6Buf;
    Bsp_t_Uart6.t_Input.us_RxBufSize = BSP_UART_6_RXBUF_SIZE;
    Bsp_t_Uart6.t_Input.tp_UartHandle = &huart6;
    Bsp_t_Uart6.t_Input.tp_DmaTxHandel = &hdma_usart6_tx;
    Bsp_t_Uart6.t_Input.tp_DmaRxHandel = &hdma_usart6_rx;
    Bsp_t_Uart6.t_Input.fnp_RxParse = Bsp_uart6_Parse;
    BspUart_Init(&Bsp_t_Uart6);
    //
    memset((char *)&Bsp_t_Uart8, 0, sizeof(BSP_UART_T_INTERFACE));
    Bsp_t_Uart8.t_Input.e_Channel = BSP_UART_CH_UART8;
    Bsp_t_Uart8.t_Input.ucp_TxBuf = Uart_Tx8Buf;
    Bsp_t_Uart8.t_Input.us_TxBufSize = BSP_UART_8_TXBUF_SIZE;
    Bsp_t_Uart8.t_Input.ucp_RxBuf = Uart_Rx8Buf;
    Bsp_t_Uart8.t_Input.us_RxBufSize = BSP_UART_8_RXBUF_SIZE;
    Bsp_t_Uart8.t_Input.tp_UartHandle = &huart8;
    Bsp_t_Uart8.t_Input.tp_DmaTxHandel = &hdma_uart8_tx;
    Bsp_t_Uart8.t_Input.tp_DmaRxHandel = &hdma_uart8_rx;
    Bsp_t_Uart8.t_Input.fnp_RxParse = Bsp_uart8_Parse;
    BspUart_Init(&Bsp_t_Uart8);
    // GPIO-IIC
    memset((char *)&Bsp_t_GpioIIC_Eeprom, 0, sizeof(Bsp_t_GpioIIC_Eeprom));
    Bsp_t_GpioIIC_Eeprom.t_Input.fnp_Delay_us = Bsp_t_Dwt.t_Output.fnp_Delay_us;
    Bsp_t_GpioIIC_Eeprom.t_Input.fnp_WritePin = Bsp_GpioIIC_WriteGpio_Eeprom;
    Bsp_t_GpioIIC_Eeprom.t_Input.fnp_ReadPin = Bsp_GpioIIC_ReadGpio_Eeprom;
    Bsp_t_GpioIIC_Eeprom.t_Input.Delay_us = 1;
    BspGpioIIC_Init(&Bsp_t_GpioIIC_Eeprom);

    memset((char *)&Bsp_t_GpioIIC_SDP800_O2, 0, sizeof(Bsp_t_GpioIIC_SDP800_O2));
    Bsp_t_GpioIIC_SDP800_O2.t_Input.fnp_Delay_us = Bsp_t_Dwt.t_Output.fnp_Delay_us;
    Bsp_t_GpioIIC_SDP800_O2.t_Input.fnp_WritePin = Bsp_GpioIIC_WriteGpio_SDP800_O2;
    Bsp_t_GpioIIC_SDP800_O2.t_Input.fnp_ReadPin = Bsp_GpioIIC_ReadGpio_SDP800_O2;
    Bsp_t_GpioIIC_SDP800_O2.t_Input.Delay_us = 1;
    BspGpioIIC_Init(&Bsp_t_GpioIIC_SDP800_O2);

    memset((char *)&Bsp_t_GpioIIC_SDP800_Out, 0, sizeof(Bsp_t_GpioIIC_SDP800_Out));
    Bsp_t_GpioIIC_SDP800_Out.t_Input.fnp_Delay_us = Bsp_t_Dwt.t_Output.fnp_Delay_us;
    Bsp_t_GpioIIC_SDP800_Out.t_Input.fnp_WritePin = Bsp_GpioIIC_WriteGpio_SDP800_Out;
    Bsp_t_GpioIIC_SDP800_Out.t_Input.fnp_ReadPin = Bsp_GpioIIC_ReadGpio_SDP800_Out;
    Bsp_t_GpioIIC_SDP800_Out.t_Input.Delay_us = 1;
    BspGpioIIC_Init(&Bsp_t_GpioIIC_SDP800_Out);

    memset((char *)&Bsp_t_GpioIIC_Bmp280, 0, sizeof(Bsp_t_GpioIIC_Bmp280));
    Bsp_t_GpioIIC_Bmp280.t_Input.fnp_Delay_us = Bsp_t_Dwt.t_Output.fnp_Delay_us;
    Bsp_t_GpioIIC_Bmp280.t_Input.fnp_WritePin = Bsp_GpioIIC_WriteGpio_Bmp280;
    Bsp_t_GpioIIC_Bmp280.t_Input.fnp_ReadPin = Bsp_GpioIIC_ReadGpio_Bmp280;
    Bsp_t_GpioIIC_Bmp280.t_Input.Delay_us = 1;
    BspGpioIIC_Init(&Bsp_t_GpioIIC_Bmp280);

    memset((char *)&Bsp_t_GpioIIC_Bq4050, 0, sizeof(Bsp_t_GpioIIC_Bq4050));
    Bsp_t_GpioIIC_Bq4050.t_Input.fnp_Delay_us = Bsp_t_Dwt.t_Output.fnp_Delay_us;
    Bsp_t_GpioIIC_Bq4050.t_Input.fnp_WritePin = Bsp_GpioIIC_WriteGpio_Bq4050;
    Bsp_t_GpioIIC_Bq4050.t_Input.fnp_ReadPin = Bsp_GpioIIC_ReadGpio_Bq4050;
    Bsp_t_GpioIIC_Bq4050.t_Input.Delay_us = 3;
    BspGpioIIC_Init(&Bsp_t_GpioIIC_Bq4050);

    memset((char *)&Bsp_t_GpioIIC_Ds1339, 0, sizeof(Bsp_t_GpioIIC_Ds1339));
    Bsp_t_GpioIIC_Ds1339.t_Input.fnp_Delay_us = Bsp_t_Dwt.t_Output.fnp_Delay_us;
    Bsp_t_GpioIIC_Ds1339.t_Input.fnp_WritePin = Bsp_GpioIIC_WriteGpio_Ds1339;
    Bsp_t_GpioIIC_Ds1339.t_Input.fnp_ReadPin = Bsp_GpioIIC_ReadGpio_Ds1339;
    Bsp_t_GpioIIC_Ds1339.t_Input.Delay_us = 1;
    BspGpioIIC_Init(&Bsp_t_GpioIIC_Ds1339);

    memset((char *)&Bsp_t_GpioIIC_SpO2, 0, sizeof(Bsp_t_GpioIIC_SpO2));
    Bsp_t_GpioIIC_SpO2.t_Input.fnp_Delay_us = Bsp_t_Dwt.t_Output.fnp_Delay_us;
    Bsp_t_GpioIIC_SpO2.t_Input.fnp_WritePin = Bsp_GpioIIC_WriteGpio_SpO2;
    Bsp_t_GpioIIC_SpO2.t_Input.fnp_ReadPin = Bsp_GpioIIC_ReadGpio_SpO2;
    Bsp_t_GpioIIC_SpO2.t_Input.fnp_GpioInit = Bsp_GpioIIC_GpioInit_SFM3000;
    Bsp_t_GpioIIC_SpO2.t_Input.Delay_us = 1;
    BspGpioIIC_Init(&Bsp_t_GpioIIC_SpO2);
    // 气源压力传感器
    memset((char *)&Bsp_t_ABPDANN150PGAA5, 0, sizeof(Bsp_t_ABPDANN150PGAA5));
    BspABPDANN150PGAA5_Init(&Bsp_t_ABPDANN150PGAA5);
    // 风机
    memset((char *)&Bsp_t_AirFan, 0, sizeof(Bsp_t_AirFan));
    Bsp_t_AirFan.t_Input.us_AdcReference_MV = BSP_ADC_REFERENCE_MV;
    Bsp_t_AirFan.t_Input.fnp_OnOff = Bsp_AirFan_On;
    Bsp_t_AirFan.t_Input.fnp_Da = Bsp_AirFan_Da;
    Bsp_t_AirFan.t_Input.fnp_GetTimCmt = Bsp_AirFan_GetTimCmt;
    Bsp_t_AirFan.t_Input.fnp_SetTimCmt = Bsp_AirFan_SetTimCmt;
    Bsp_t_AirFan.t_Input.fnp_DebugOnCallback = Bsp_AirFan_DebugOnCallback;
    Bsp_t_AirFan.t_Input.fnp_DebugOffCallback = Bsp_AirFan_DebugOffCallback;
    Bsp_t_AirFan.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspAirFan_Init(&Bsp_t_AirFan);
    HAL_TIM_Base_Start(BSP_AIRFAN_FREQ_TIMX);
    // 报警CPU
    memset((char *)&Bsp_t_AlarmCPU, 0, sizeof(Bsp_t_AlarmCPU));
    Bsp_t_AlarmCPU.t_Input.fnp_UartTx = Bsp_AlarmCPU_TxFun;
    BspAlarm_Init(&Bsp_t_AlarmCPU);
    // 环境温度、环境压力传感器
    memset((char *)&Bsp_t_Bsp280, 0, sizeof(Bsp_t_Bsp280));
    Bsp_t_Bsp280.t_Input.tp_GpioIIC = &Bsp_t_GpioIIC_Bmp280;
    Bsp_t_Bsp280.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspBmp280_Init(&Bsp_t_Bsp280);
    // 电池管理芯片
    memset((char *)&Bsp_t_Bq4050, 0, sizeof(Bsp_t_Bq4050));
    Bsp_t_Bq4050.t_Input.tp_GpioIIC = &Bsp_t_GpioIIC_Bq4050;
    Bsp_t_Bq4050.t_Input.fnp_OsDelay_ms = Bsp_Bq4050_OsDelay_ms;
    Bsp_t_Bq4050.t_Input.fnp_WriteGpioPower = Bsp_Bq4050_WriteGpioPower;
    Bsp_t_Bq4050.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspBq4050_Init(&Bsp_t_Bq4050);
    // Cpu
    memset((char *)&Bsp_t_Cpu, 0, sizeof(Bsp_t_Cpu));
    Bsp_t_Cpu.t_Input.e_Cpu = BSP_CPU_E_CPU_STM32H7;
    Bsp_t_Cpu.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspCpu_Init(&Bsp_t_Cpu);
    // 外部RTC
    memset((char *)&Bsp_t_Ds1339, 0, sizeof(Bsp_t_Ds1339));
    Bsp_t_Ds1339.t_Input.tp_GpioIIC = &Bsp_t_GpioIIC_Ds1339;
    BspDs1339_Init(&Bsp_t_Ds1339);
    // 呼末二氧化碳模块
    memset((char *)&Bsp_EtCO2_s, 0, sizeof(Bsp_EtCO2_s));
    Bsp_EtCO2_s.t_Input.t_Module = BSP_ETCO2_E_MODULE_CM2200;
    Bsp_EtCO2_s.t_Input.fnp_WriteGpioPower = Bsp_EtCO2_WriteGpioPower;
    Bsp_EtCO2_s.t_Input.fnp_InitUart = Bsp_EtCO2_InitUart;
    Bsp_EtCO2_s.t_Input.fnp_TxData = Bsp_EtCO2_UartTx;
    Bsp_EtCO2_s.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspETCO2_Init(&Bsp_EtCO2_s);
    HAL_TIM_Base_Start_IT(&htim7);
    // 风扇
    memset((char *)&Bsp_t_Fan, 0, sizeof(Bsp_t_Fan));
    Bsp_t_Fan.t_Input.fnp_ReadGpioPwm = Bsp_Fan_ReadGpioPwm;
    Bsp_t_Fan.t_Input.fnp_WriteGpioPower = Bsp_Fan_WriteGpioPower;
    Bsp_t_Fan.t_Input.fnp_WriteGpioPwm = Bsp_Fan_WriteGpioPwm;
    Bsp_t_Fan.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    Bsp_t_Fan.t_Input.fnp_WriteGpioPower(true);
    Bsp_t_Fan.t_Input.fnp_WriteGpioPwm(false);
    BspFan_Init(&Bsp_t_Fan);
    // 按键
    memset((char *)&Bsp_t_Key1, 0, sizeof(Bsp_t_Key1));
    Bsp_t_Key1.t_Input.fnp_PressCondition = Bsp_Key1_PressedCondition;
    Bsp_t_Key1.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspKey_Init(&Bsp_t_Key1);
    memset((char *)&Bsp_t_Key2, 0, sizeof(Bsp_t_Key2));
    Bsp_t_Key2.t_Input.fnp_PressCondition = Bsp_Key2_PressedCondition;
    Bsp_t_Key2.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspKey_Init(&Bsp_t_Key2);
    // LED
    memset((char *)&Bsp_t_Led1, 0, sizeof(Bsp_t_Led1));
    Bsp_t_Led1.t_Input.fnp_LedOnOff = Bsp_Led1_OnOff;
    Bsp_t_Led1.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspLed_Init(&Bsp_t_Led1);
    memset((char *)&Bsp_t_Led2, 0, sizeof(Bsp_t_Led2));
    Bsp_t_Led2.t_Input.fnp_LedOnOff = Bsp_Led2_OnOff;
    Bsp_t_Led2.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspLed_Init(&Bsp_t_Led2);
    memset((char *)&Bsp_t_Led3, 0, sizeof(Bsp_t_Led3));
    Bsp_t_Led3.t_Input.fnp_LedOnOff = Bsp_Led3_OnOff;
    Bsp_t_Led3.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspLed_Init(&Bsp_t_Led3);
    memset((char *)&Bsp_t_Led4, 0, sizeof(Bsp_t_Led4));
    Bsp_t_Led4.t_Input.fnp_LedOnOff = Bsp_Led4_OnOff;
    Bsp_t_Led4.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspLed_Init(&Bsp_t_Led4);
    memset((char *)&Bsp_t_Led5, 0, sizeof(Bsp_t_Led5));
    Bsp_t_Led5.t_Input.fnp_LedOnOff = Bsp_Led5_OnOff;
    Bsp_t_Led5.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspLed_Init(&Bsp_t_Led5);
    memset((char *)&Bsp_t_Led6, 0, sizeof(Bsp_t_Led6));
    Bsp_t_Led6.t_Input.fnp_LedOnOff = Bsp_Led6_OnOff;
    Bsp_t_Led6.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspLed_Init(&Bsp_t_Led6);
    // 电池充电
    memset((char *)&Bsp_t_Ltc4015Interface, 0, sizeof(Bsp_t_Ltc4015Interface));
    Bsp_t_Ltc4015Interface.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    Bsp_t_Ltc4015Interface.t_Input.tp_GpioIIC = &Bsp_t_GpioIIC_Bq4050;
    Bsp_t_Ltc4015Interface.t_Input.fnp_ReadGpioPower = Bsp_Ltc4015_ReadGpioPower;
    Bsp_t_Ltc4015Interface.t_Input.fnp_WriteGpioPower = Bsp_Ltc4015_WriteGpioPower;
    Bsp_t_Ltc4015Interface.t_Input.ul_IIN_ma = 6000L;
    Bsp_t_Ltc4015Interface.t_Input.f_BatCapacity_AH = 13.4f;
    Bsp_t_Ltc4015Interface.t_Input.fnp_WriteGpioPower(true);
    BspLtc4015_Init(&Bsp_t_Ltc4015Interface);
    // 管路压力传感器
    memset((char *)&Bsp_t_MPXV4006GC6U_Out, 0, sizeof(Bsp_t_MPXV4006GC6U_Out));
    BspMPXV4006GC6U_Init(&Bsp_t_MPXV4006GC6U_Out);
    memset((char *)&Bsp_t_MPXV4006GC6U_Mask, 0, sizeof(Bsp_t_MPXV4006GC6U_Mask));
    BspMPXV4006GC6U_Init(&Bsp_t_MPXV4006GC6U_Mask);
    // 辅助压力传感器
    memset((char *)&Bsp_t_MPXV70xxGC6U, 0, sizeof(Bsp_t_MPXV70xxGC6U));
    Bsp_t_MPXV70xxGC6U.t_Input.t_Chip = BSP_MPXV70XXGC6U_E_CHIP_7025;
    BspMPXV70xxGC6U_Init(&Bsp_t_MPXV70xxGC6U);
    // 雾化驱动
    memset((char *)&Bsp_t_Nebulizer, 0, sizeof(Bsp_t_Nebulizer));
    Bsp_t_Nebulizer.t_Input.fnp_WriteGpioPower = Bsp_Nebulizer_WriteGpioPower;
    Bsp_t_Nebulizer.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    Bsp_t_Nebulizer.t_Input.fnp_WriteGpioPower(false);
    BspNebulizer_Init(&Bsp_t_Nebulizer);
    // 管路氧浓度
    memset((char *)&Bsp_t_Ocs3fa_Pipe, 0, sizeof(Bsp_t_Ocs3fa_Pipe));
    Bsp_t_Ocs3fa_Pipe.t_Input.fnp_TxData = Bsp_Ocs3fa_Pipe_TxFun;
    Bsp_t_Ocs3fa_Pipe.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspOcs3fa_Init(&Bsp_t_Ocs3fa_Pipe);
    // 环境氧浓度
    memset((char *)&Bsp_t_Ocs3fa_Environment, 0, sizeof(Bsp_t_Ocs3fa_Environment));
    Bsp_t_Ocs3fa_Environment.t_Input.fnp_TxData = Bsp_Ocs3fa_Internal_TxFun;
    Bsp_t_Ocs3fa_Environment.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspOcs3fa_Init(&Bsp_t_Ocs3fa_Environment);
    // 比例阀
    memset((char *)&Bsp_t_ProportionalValves, 0, sizeof(Bsp_t_ProportionalValves));
    Bsp_t_ProportionalValves.t_Input.t_Module = (BSP_PROPORTIONAL_VALVES_MODULE)AppBipapInterface_t_SetPara.ModuleSelect_PROPORTIONAL_VALVES;
    Bsp_t_ProportionalValves.t_Input.us_Pwm = 0;
    Bsp_t_ProportionalValves.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspProportionalValves_Init(&Bsp_t_ProportionalValves);
    // EERROM
    memset((char *)&Bsp_t_Eeprom, 0, sizeof(Bsp_t_Eeprom));
    Bsp_t_Eeprom.t_Input.tp_GpioIIC = &Bsp_t_GpioIIC_Eeprom;
    Bsp_t_Eeprom.t_Input.uc_Addr = 0xA0;
    Bsp_t_Eeprom.t_Input.fnp_Delay_us = Bsp_t_Dwt.t_Output.fnp_Delay_us;
    Bsp_t_Eeprom.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    Bsp_t_Eeprom.t_Input.fnp_Debug_InputNum = Bsp_DebugInputNum;
    BspEeprom_Init(&Bsp_t_Eeprom);
    //  出口压差
    memset((char *)&Bsp_t_Sdp800_Out, 0, sizeof(Bsp_t_Sdp800_Out));
    Bsp_t_Sdp800_Out.t_Input.tp_GpioIIC = &Bsp_t_GpioIIC_SDP800_Out;
    Bsp_t_Sdp800_Out.t_Input.t_Chip = BSP_SDP500_E_CHIP_SDP800;
    Bsp_t_Sdp800_Out.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspSdp500_Init(&Bsp_t_Sdp800_Out);
    // 氧气压差
    memset((char *)&Bsp_t_Sdp800_O2, 0, sizeof(Bsp_t_Sdp800_O2));
    Bsp_t_Sdp800_O2.t_Input.tp_GpioIIC = &Bsp_t_GpioIIC_SDP800_O2;
    Bsp_t_Sdp800_O2.t_Input.t_Chip = BSP_SDP500_E_CHIP_SDP800;
    Bsp_t_Sdp800_O2.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspSdp500_Init(&Bsp_t_Sdp800_O2);
    // 流量传感器
    memset((char *)&Bsp_t_SFM3000, 0, sizeof(Bsp_t_SFM3000));
    Bsp_t_SFM3000.t_Input.tp_GpioIIC = &Bsp_t_GpioIIC_SpO2;
    Bsp_t_SFM3000.t_Input.BspSfm3000_OnOff = false;
    Bsp_t_SFM3000.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspSfm3000_Init(&Bsp_t_SFM3000);
    // 血氧传感器
    memset((char *)&Bsp_SpO2_s_Data, 0, sizeof(Bsp_SpO2_s_Data));
    Bsp_SpO2_s_Data.t_Input.fnp_PwrOn = Bsp_SpO2_On;
    Bsp_SpO2_s_Data.t_Input.fnp_TxData = Bsp_SpO2_UartTx;
    Bsp_SpO2_s_Data.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    Bsp_SpO2_s_Data.t_Input.fnp_PwrOn(true);
    BspSpO2_Init(&Bsp_SpO2_s_Data);
    //
    BspDac_Init(0);
    // 其他引脚初始化
    HAL_GPIO_WritePin(GPIO_PATH_ACDC_GPIO_Port, GPIO_PATH_ACDC_Pin, GPIO_PIN_SET);
    HAL_GPIO_WritePin(GPIO_PATH_INT_GPIO_Port, GPIO_PATH_INT_Pin, GPIO_PIN_SET);
    HAL_GPIO_WritePin(GPIO_PATH_BAT_GPIO_Port, GPIO_PATH_BAT_Pin, GPIO_PIN_SET);
    HAL_GPIO_WritePin(GPIO_PATH_SYS_GPIO_Port, GPIO_PATH_SYS_Pin, GPIO_PIN_SET);
    // 模块层-算法模块
    memset((char *)&ModuleCount_t_Interface, 0, sizeof(ModuleCount_t_Interface));
    ModuleCount_t_Interface.t_Input.fnp_Delay_ms = Bsp_t_Dwt.t_Output.fnp_Delay_ms;
    ModuleCount_t_Interface.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    ModuleCount_Init(&ModuleCount_t_Interface);
    //
    ModuleAes128_t_Interface.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    ModuleAes128_t_Interface.t_Input.fnp_DebugOutHex = Bsp_DebugOutHex;
    // 应用层-自测模块
    memset((char *)&Bsp_t_AppDebug, 0, sizeof(Bsp_t_AppDebug));
    AppDebug_Init(&Bsp_t_AppDebug);
    // 模块层-自测模块
    memset((char *)&Bsp_t_ModuleDebug, 0, sizeof(Bsp_t_ModuleDebug));
    Bsp_t_ModuleDebug.t_Input.fnp_OsDelay_ms = Bsp_OsDelay_ms;
    Bsp_t_ModuleDebug.t_Input.tp_MenuTab = Bsp_t_AppDebug.t_Output.tp_MenuTab;
    Bsp_t_ModuleDebug.t_Input.us_MenuTabSize = Bsp_t_AppDebug.t_Output.us_MenuTabSize;
    Bsp_t_ModuleDebug.t_Input.e_LogLevel = MODULE_DEBUG_E_LEVEL_INFO;
    // Bsp_t_ModuleDebug.t_Input.fnp_Tx = Bsp_t_AppDebug.t_Output.fnp_Tx;
    Bsp_t_ModuleDebug.t_Input.fnp_Tx = Bsp_SeggerRtt_WriteStr;
    Bsp_t_ModuleDebug.t_Input.fnp_NoBlockingRx = Bsp_SeggerRtt_NoBlockingRead;
    Bsp_t_ModuleDebug.t_Input.cp_HardwareVer = APP_VERSION_HARDWARE_VER_STR;
    Bsp_t_ModuleDebug.t_Input.cp_ProjectName = APP_VERSION_PRODUCT_NAME;
    Bsp_t_ModuleDebug.t_Input.cp_SoftwareVer = APP_VERSION_SOFTWARE_VER_STR;
    Bsp_t_ModuleDebug.t_Input.ucp_CurrentTime_6B = BspRtc_CurrentTimeBuf;
    ModuleDebug_Init(&Bsp_t_ModuleDebug);
    // 模块层-单元测试
    memset((char *)&Bsp_t_ModuleUnity, 0, sizeof(Bsp_t_ModuleUnity));
    Bsp_t_ModuleUnity.t_Input.fnp_Tx = Bsp_SeggerRtt_WriteStr;
    ModuleUnity_Init(&Bsp_t_ModuleUnity);
}
/**
 * @brief
 */
void Bsp_Cycle_1ms(void)
{
    Bsp_t_Sdp800_Out.t_Transplant.fnp_GetData(&Bsp_t_Sdp800_Out);
    Bsp_t_Sdp800_O2.t_Transplant.fnp_GetData(&Bsp_t_Sdp800_O2);
    Bsp_t_SFM3000.t_Transplant.fnp_GetData(&Bsp_t_SFM3000);
    Bsp_t_Fan.t_Transplant.fnp_Cycle_1ms(&Bsp_t_Fan);
    Bsp_t_AirFan.t_Transplant.fnp_Cycle_1ms(&Bsp_t_AirFan);
    Bsp_t_Led1.t_Transplant.fnp_Cycle_1ms(&Bsp_t_Led1);
    Bsp_t_Led2.t_Transplant.fnp_Cycle_1ms(&Bsp_t_Led2);
    Bsp_t_Led3.t_Transplant.fnp_Cycle_1ms(&Bsp_t_Led3);
    Bsp_t_Led4.t_Transplant.fnp_Cycle_1ms(&Bsp_t_Led4);
    Bsp_t_Led5.t_Transplant.fnp_Cycle_1ms(&Bsp_t_Led5);
    Bsp_t_Led6.t_Transplant.fnp_Cycle_1ms(&Bsp_t_Led6);
    Module_AES128_1msPro();
}
/**
 * @brief
 */
void Bsp_Cycle_10ms(void)
{
    Bsp_t_Key1.t_Transplant.fnp_Cycle_10ms(&Bsp_t_Key1);
    Bsp_t_Key2.t_Transplant.fnp_Cycle_10ms(&Bsp_t_Key2);
}
/**
 * @brief
 */
void Bsp_Cycle_100ms(void)
{
    Bsp_Adc_Cycle_100ms();
    Bsp_t_Led1.t_Output.fnp_SetMode(&Bsp_t_Led1, BSP_LED_E_MODE_TOGGLE, BSP_LED_E_PRIORITY_LOW);
    /*BspUsbHostUDisk_Cycle_100ms();*/
    Bsp_t_Led1.t_Transplant.fnp_Cycle_100ms(&Bsp_t_Led1);
    Bsp_t_Led2.t_Transplant.fnp_Cycle_100ms(&Bsp_t_Led2);
    Bsp_t_Led3.t_Transplant.fnp_Cycle_100ms(&Bsp_t_Led3);
    Bsp_t_Led4.t_Transplant.fnp_Cycle_100ms(&Bsp_t_Led4);
    Bsp_t_Led5.t_Transplant.fnp_Cycle_100ms(&Bsp_t_Led5);
    Bsp_t_Led6.t_Transplant.fnp_Cycle_100ms(&Bsp_t_Led6);
    Bsp_t_Sdp800_Out.t_Transplant.fnp_Cycle_100ms(&Bsp_t_Sdp800_Out);
    Bsp_t_Sdp800_O2.t_Transplant.fnp_Cycle_100ms(&Bsp_t_Sdp800_O2);
    Bsp_t_SFM3000.t_Transplant.fnp_Cycle_100ms(&Bsp_t_SFM3000);
    Bsp_t_AirFan.t_Transplant.fnp_Cycle_100ms(&Bsp_t_AirFan);
    Bsp_t_Ocs3fa_Pipe.t_Transplant.fnp_Cycle_100ms(&Bsp_t_Ocs3fa_Pipe);
    Bsp_t_Ocs3fa_Environment.t_Transplant.fnp_Cycle_100ms(&Bsp_t_Ocs3fa_Environment);
    Bsp_t_Bsp280.t_Transplant.fnp_Cycle_100ms(&Bsp_t_Bsp280);
    Bsp_t_Ltc4015Interface.t_Transplant.fnp_Cycle_100ms(&Bsp_t_Ltc4015Interface);
    Bsp_EtCO2_s.t_Transplant.fnp_Cycle_100ms(&Bsp_EtCO2_s);
    Bsp_SpO2_s_Data.t_Transplant.fnp_Cycle_100ms(&Bsp_SpO2_s_Data);
    Bsp_t_Fan.t_Transplant.fnp_Cycle_100ms(&Bsp_t_Fan);
    Bsp_t_ProportionalValves.t_Transplant.fnp_Cycle_100ms(&Bsp_t_ProportionalValves);
    Bsp_t_Ds1339.t_Transplant.fnp_Cycle_100ms(&Bsp_t_Ds1339);
    Bsp_t_AlarmCPU.t_Transplant.fnp_Cycle_100ms(&Bsp_t_AlarmCPU);
}
/**
 * @brief
 */
void Bsp_Cycle_1000ms(void)
{
    Bsp_t_Key1.t_Transplant.fnp_Cycle_1000ms(&Bsp_t_Key1);
    Bsp_t_Key2.t_Transplant.fnp_Cycle_1000ms(&Bsp_t_Key2);
    Bsp_t_Nebulizer.t_Transplant.fnp_Cycle_1000ms(&Bsp_t_Nebulizer);
    Bsp_t_Bq4050.t_Transplant.fnp_Cycle_1000ms(&Bsp_t_Bq4050);
    Bsp_LedDebugCycle_1000ms();
}
/**
 * @brief
 */
void Bsp_RtcCycle_1000ms(void)
{
    Bsp_t_Led2.t_Output.fnp_SetMode(&Bsp_t_Led2, BSP_LED_E_MODE_TOGGLE, BSP_LED_E_PRIORITY_LOW);
}
/**
 * @brief 周期执行函数,用于Debug测试等,应该放在Debug任务
 */
void Bsp_Debug_100ms(void)
{
    static uint8_t si = 0;
    char *pbuf;
    uint8_t res = false;
    si++;
    if (si >= 10)
    {
        si = 0;
        // 任务异常判断
        do
        {
            static uint32_t Main_TaskStart_Cmt_bak = 0;
            static uint32_t Main_TaskDebug_Cmt_bak = 0;
            static uint32_t Main_TaskGui_Cmt_bak = 0;
            static uint32_t Main_TaskControl_Cmt_bak = 0;
            static uint8_t s_init_timer = 10;
            // 初始化一段时间内不判断
            if (s_init_timer != 0)
            {
                s_init_timer--;
                break;
            }
            if ((Main_TaskStart_Cmt == Main_TaskStart_Cmt_bak) ||
                (Main_TaskDebug_Cmt == Main_TaskDebug_Cmt_bak) ||
                (Main_TaskGui_Cmt == Main_TaskGui_Cmt_bak) ||
                (Main_TaskControl_Cmt == Main_TaskControl_Cmt_bak))
            {
                Bsp_DebugOutStr("Task Cmt Error!!!\r\n");
                res = true;
            }
        } while (0);
        // 内存管理临界
        if ((MemManager_Mem_256B_MaxNum == MEM_256B_BLK_NBR) ||
            (MemManager_Mem_1KB_MaxNum == MEM_1KB_BLK_NBR) ||
            (MemManager_Mem_2KB_Basic_MaxNum == MEM_2KB_BASIC_BLK_NBR) ||
            (MemManager_Mem_5KB_Basic_MaxNum == MEM_5KB_BASIC_BLK_NBR) ||
            (MemManager_Mem_10KB_MaxNum == MEM_10KB_BLK_NBR) ||
            (MemManager_Mem_128KB_MaxNum == MEM_128KB_BLK_NBR))
        {
            pbuf = ModuleMemManager_Get(E_MEM_MANAGER_TYPE_256B);
            Bsp_DebugOutStr("MemInfo:  Num Max Size\r\n");
            sprintf((char *)pbuf, "Mem-256B  = %d   %d   %d\r\n", MemManager_Mem_256B_Num, MemManager_Mem_256B_MaxNum, MEM_256B_BLK_NBR);
            Bsp_DebugOutStr((int8_t *)pbuf);
            sprintf((char *)pbuf, "Mem-1KB   = %d   %d   %d\r\n", MemManager_Mem_1KB_Num, MemManager_Mem_1KB_MaxNum, MEM_1KB_BLK_NBR);
            Bsp_DebugOutStr((int8_t *)pbuf);
            sprintf((char *)pbuf, "Mem-2KB   = %d   %d   %d\r\n", MemManager_Mem_2KB_Basic_Num, MemManager_Mem_2KB_Basic_MaxNum, MEM_2KB_BASIC_BLK_NBR);
            Bsp_DebugOutStr((int8_t *)pbuf);
            sprintf((char *)pbuf, "Mem-5KB   = %d   %d   %d\r\n", MemManager_Mem_5KB_Basic_Num, MemManager_Mem_5KB_Basic_MaxNum, MEM_5KB_BASIC_BLK_NBR);
            Bsp_DebugOutStr((int8_t *)pbuf);
            sprintf((char *)pbuf, "Mem-10KB  = %d   %d   %d\r\n", MemManager_Mem_10KB_Num, MemManager_Mem_10KB_MaxNum, MEM_10KB_BLK_NBR);
            Bsp_DebugOutStr((int8_t *)pbuf);
            sprintf((char *)pbuf, "Mem-128KB = %d   %d   %d\r\n", MemManager_Mem_128KB_Num, MemManager_Mem_128KB_MaxNum, MEM_128KB_BLK_NBR);
            Bsp_DebugOutStr((int8_t *)pbuf);
            ModuleMemManager_Free(E_MEM_MANAGER_TYPE_256B, pbuf);
        }
        //
        if ((uc_DebugTestEnable == 1) || (res == true))
        {
            // 申请缓存
            pbuf = ModuleMemManager_Get(E_MEM_MANAGER_TYPE_256B);
            // 打印输出
            sprintf(pbuf, "----------\r\n");
            Bsp_DebugOutStr((int8_t *)pbuf);
            sprintf(pbuf, "Main_TaskStart_Cmt  - %u\r\n", Main_TaskStart_Cmt);
            Bsp_DebugOutStr((int8_t *)pbuf);
            sprintf(pbuf, "Main_TaskDebug_Cmt  - %u\r\n", Main_TaskDebug_Cmt);
            Bsp_DebugOutStr((int8_t *)pbuf);
            sprintf(pbuf, "Main_TaskGui_Cmt    - %u\r\n", Main_TaskGui_Cmt);
            Bsp_DebugOutStr((int8_t *)pbuf);
            sprintf(pbuf, "Main_TaskControl_Cmt- %u\r\n", Main_TaskControl_Cmt);
            Bsp_DebugOutStr((int8_t *)pbuf);
            // 释放缓存
            ModuleMemManager_Free(E_MEM_MANAGER_TYPE_256B, pbuf);
        }
        // 堆栈溢出判断
    }
}
/**
 * @brief Debug接口函数，开启后会循环打印调试信息
 * @param[in]  OnOff        进入与退出
 */
void Bsp_DebugTestOnOff(uint8_t OnOff, void *_vp_context)
{
    if (OnOff == true)
    {
        uc_DebugTestEnable = 1;
    }
    else
    {
        uc_DebugTestEnable = 0;
    }
}
/**
 * @brief Debug接口函数，开启后会进入St芯片的厂家Boot区
 * @param[in]  OnOff        进入与退出
 */
void Bsp_Debug_IAP(uint8_t OnOff, void *_vp_context)
{
    OnOff = OnOff;
    char *pbuf;
    // 申请缓存
    pbuf = ModuleMemManager_Get(E_MEM_MANAGER_TYPE_256B);
    // 打印输出
    sprintf(pbuf, "Please Power Off To On!\r\n");
    Bsp_DebugOutStr((int8_t *)pbuf);
    // 释放缓存
    ModuleMemManager_Free(E_MEM_MANAGER_TYPE_256B, pbuf);

    Bootloader_PreToStBoot();
    while (1)
    {
        ;
    }
}
/**
 * @brief Debug接口函数，开启后会进入手工输入各种Sn与版本号流程
 * @param[in]  OnOff        进入与退出
 */
void Bsp_Debug_Write_Info(uint8_t _uc_OnOff, void *_vp_context)
{
    uint16_t len;
    uint8_t *pbuf;
    pbuf = ModuleMemManager_Get(E_MEM_MANAGER_TYPE_256B);
    //
    Bsp_DebugOutStr((int8_t *)"----------\r\n");
    memcpy(&pbuf[200], ModuleMemory_psnPara->Machine_Sn_StrBuf, sizeof(ModuleMemory_psnPara->Machine_Sn_StrBuf));
    sprintf((char *)pbuf, "Current - Machine_Sn_StrBuf  : %.18s\r\n", (char *)&pbuf[200]);
    Bsp_DebugOutStr((int8_t *)pbuf);
    //
    memcpy(&pbuf[200], ModuleMemory_psnPara->Component_SN_StrBuf, sizeof(ModuleMemory_psnPara->Component_SN_StrBuf));
    sprintf((char *)pbuf, "Current - Component_SN_StrBuf: %.18s\r\n", (char *)&pbuf[200]);
    Bsp_DebugOutStr((int8_t *)pbuf);
    //
    memcpy(&pbuf[200], ModuleMemory_psnPara->HardWare_Ver_StrBuf, sizeof(ModuleMemory_psnPara->HardWare_Ver_StrBuf));
    sprintf((char *)pbuf, "Current - HardWare_Ver_StrBuf: %.8s\r\n", (char *)&pbuf[200]);
    Bsp_DebugOutStr((int8_t *)pbuf);
    Bsp_DebugOutStr((int8_t *)"----------\r\n");
    //
    for (pbuf[252] = 0; pbuf[252] < 3; pbuf[252]++)
    {
        //
        if (pbuf[252] == 0)
        {
            pbuf[253] = 18;
        }
        else if (pbuf[252] == 1)
        {
            pbuf[253] = 18;
        }
        else if (pbuf[252] == 2)
        {
            pbuf[253] = 8;
        }
        //
        while (1)
        {
            // 打印提示信息
            if (pbuf[252] == 0)
            {
                Bsp_DebugOutStr((int8_t *)"Please Input Machine Sn (18 char or '0'-NULL):\r\n");
            }
            else if (pbuf[252] == 1)
            {
                Bsp_DebugOutStr((int8_t *)"Please Input Component Sn (18 char or '0'-NULL):\r\n");
            }
            else if (pbuf[252] == 2)
            {
                Bsp_DebugOutStr((int8_t *)"Please Input HardWare_Ver (8 char or '0'-NULL):\r\n");
            }
            else
            {
                break;
            }
            // 输入字符
            for (pbuf[250] = 0; pbuf[250] < pbuf[253];)
            {
                Bsp_t_ModuleDebug.t_Output.fnp_DebugIn(&Bsp_t_ModuleDebug, (int8_t *)&pbuf[251], &len);
                if (len == 1 && pbuf[251] == 27)
                {
                    break;
                }
                else if (len == 1 && pbuf[251] == '\r')
                {
                    break;
                }
                else if (len == 1 && pbuf[251] == '\n')
                {
                    continue;
                }
                else if (len == 1)
                {
                    pbuf[pbuf[250]] = pbuf[251];
                }
                pbuf[250]++;
            }
            // 单0不操作
            if (pbuf[250] == 1 && pbuf[0] == '0')
            {
                break;
            }
            // 输入不是个字符,重新操作
            if (pbuf[250] != pbuf[253])
            {
                continue;
            }
            pbuf[pbuf[250]] = 0;
            // 存储
            {
                MODULE_MEMORY_SN_HW_S_PARA *pPara;
                pPara = ModuleMemManager_Get(E_MEM_MANAGER_TYPE_PAPA);
                // Module_Memory_App(MODULE_MEMORY_APP_CMD_GLOBAL_R, (uint8_t *)pPara, NULL);
                memcpy((char *)pPara, (char *)ModuleMemory_psnPara, sizeof(MODULE_MEMORY_SN_HW_S_PARA));
                if (pbuf[252] == 0)
                {
                    pPara->Flag = 0x12345678;
                    memcpy(pPara->Machine_Sn_StrBuf, pbuf, sizeof(pPara->Machine_Sn_StrBuf));
                }
                else if (pbuf[252] == 1)
                {
                    pPara->Flag = 0x12345678;
                    memcpy(pPara->Component_SN_StrBuf, pbuf, sizeof(pPara->Component_SN_StrBuf));
                }
                else if (pbuf[252] == 2)
                {
                    pPara->Flag = 0x12345678;
                    memcpy(pPara->HardWare_Ver_StrBuf, pbuf, sizeof(pPara->HardWare_Ver_StrBuf));
                }
                Module_Memory_App(MODULE_MEMORY_APP_CMD_SN_W, (uint8_t *)pPara, NULL);
                ModuleMemManager_Free(E_MEM_MANAGER_TYPE_PAPA, pPara);
            }
            break;
        }
        //
        if (pbuf[250] == pbuf[253])
        {
            if (pbuf[252] == 0)
            {
                Bsp_DebugOutStr((int8_t *)"Write Machine Sn OK!\r\n");
            }
            else if (pbuf[252] == 1)
            {
                Bsp_DebugOutStr((int8_t *)"Write Component Sn OK!\r\n");
            }
            else if (pbuf[252] == 2)
            {
                Bsp_DebugOutStr((int8_t *)"Write HardWare Ver OK!\r\n");
            }
        }
        else
        {
            if (pbuf[252] == 0)
            {
                Bsp_DebugOutStr((int8_t *)"Write Machine_Sn NULL!\r\n");
            }
            else if (pbuf[252] == 1)
            {
                Bsp_DebugOutStr((int8_t *)"Write Component_Sn NULL!\r\n");
            }
            else if (pbuf[252] == 2)
            {
                Bsp_DebugOutStr((int8_t *)"Write HardWare Ver NULL!\r\n");
            }
        }
    }
    //
    ModuleMemManager_Free(E_MEM_MANAGER_TYPE_256B, pbuf);
}
/**
 * @brief   Debug接口函数
 * @note    开启Debug相关指令后会循环打印
 * @param   OnOff-判断指令进入与退出
 * @return  None
 */
void BspAdc_DebugTestOnOff(uint8_t OnOff, void *_vp_context)
{
    if (OnOff == true)
    {
        BspAdc_DebugTest_Enable = 1;
    }
    else
    {
        BspAdc_DebugTest_Enable = 0;
    }
}
static void Bsp_LedDebugCycle_1000ms(void)
{
    static uint8_t uc_cmt = 0;
    if (uc_LedDebugEnable == 1)
    {
        uc_cmt++;
        switch (uc_cmt)
        {
        case 1:
            Bsp_t_Led1.t_Output.fnp_SetMode(&Bsp_t_Led1, BSP_LED_E_MODE_ON, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led2.t_Output.fnp_SetMode(&Bsp_t_Led2, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led3.t_Output.fnp_SetMode(&Bsp_t_Led3, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led4.t_Output.fnp_SetMode(&Bsp_t_Led4, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led5.t_Output.fnp_SetMode(&Bsp_t_Led5, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led6.t_Output.fnp_SetMode(&Bsp_t_Led6, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            break;
        case 2:
            Bsp_t_Led1.t_Output.fnp_SetMode(&Bsp_t_Led1, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led2.t_Output.fnp_SetMode(&Bsp_t_Led2, BSP_LED_E_MODE_ON, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led3.t_Output.fnp_SetMode(&Bsp_t_Led3, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led4.t_Output.fnp_SetMode(&Bsp_t_Led4, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led5.t_Output.fnp_SetMode(&Bsp_t_Led5, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led6.t_Output.fnp_SetMode(&Bsp_t_Led6, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            break;
        case 3:
            Bsp_t_Led1.t_Output.fnp_SetMode(&Bsp_t_Led1, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led2.t_Output.fnp_SetMode(&Bsp_t_Led2, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led3.t_Output.fnp_SetMode(&Bsp_t_Led3, BSP_LED_E_MODE_ON, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led4.t_Output.fnp_SetMode(&Bsp_t_Led4, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led5.t_Output.fnp_SetMode(&Bsp_t_Led5, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led6.t_Output.fnp_SetMode(&Bsp_t_Led6, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            break;
        case 4:
            Bsp_t_Led1.t_Output.fnp_SetMode(&Bsp_t_Led1, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led2.t_Output.fnp_SetMode(&Bsp_t_Led2, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led3.t_Output.fnp_SetMode(&Bsp_t_Led3, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led4.t_Output.fnp_SetMode(&Bsp_t_Led4, BSP_LED_E_MODE_ON, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led5.t_Output.fnp_SetMode(&Bsp_t_Led5, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led6.t_Output.fnp_SetMode(&Bsp_t_Led6, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            break;
        case 5:
            Bsp_t_Led1.t_Output.fnp_SetMode(&Bsp_t_Led1, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led2.t_Output.fnp_SetMode(&Bsp_t_Led2, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led3.t_Output.fnp_SetMode(&Bsp_t_Led3, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led4.t_Output.fnp_SetMode(&Bsp_t_Led4, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led5.t_Output.fnp_SetMode(&Bsp_t_Led5, BSP_LED_E_MODE_ON, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led6.t_Output.fnp_SetMode(&Bsp_t_Led6, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            break;
        case 6:
            Bsp_t_Led1.t_Output.fnp_SetMode(&Bsp_t_Led1, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led2.t_Output.fnp_SetMode(&Bsp_t_Led2, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led3.t_Output.fnp_SetMode(&Bsp_t_Led3, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led4.t_Output.fnp_SetMode(&Bsp_t_Led4, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led5.t_Output.fnp_SetMode(&Bsp_t_Led5, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led6.t_Output.fnp_SetMode(&Bsp_t_Led6, BSP_LED_E_MODE_ON, BSP_LED_E_PRIORITY_HIGH);
            break;
        default:
            uc_cmt = 0;
            Bsp_t_Led1.t_Output.fnp_SetMode(&Bsp_t_Led1, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led2.t_Output.fnp_SetMode(&Bsp_t_Led2, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led3.t_Output.fnp_SetMode(&Bsp_t_Led3, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led4.t_Output.fnp_SetMode(&Bsp_t_Led4, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led5.t_Output.fnp_SetMode(&Bsp_t_Led5, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_Led6.t_Output.fnp_SetMode(&Bsp_t_Led6, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            break;
        }
    }
    else
    {
        uc_cmt = 0;
    }
}
/**
 * @brief   Debug接口函数
 * @note    开启Debug相关指令后会循环点亮，关闭Debug后所有LED全部关闭
 * @param   _uc_trueOrFalse-判断指令进入与退出
 * @return  None
 */
void Bsp_LedDebugTestOnOff(uint8_t _uc_trueOrFalse, void *_vp_context)
{
    if (_uc_trueOrFalse == true)
    {
        uc_LedDebugEnable = 1;
        Bsp_t_Led1.t_Output.fnp_SetMode(&Bsp_t_Led1, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
        Bsp_t_Led2.t_Output.fnp_SetMode(&Bsp_t_Led2, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
        Bsp_t_Led3.t_Output.fnp_SetMode(&Bsp_t_Led3, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
        Bsp_t_Led4.t_Output.fnp_SetMode(&Bsp_t_Led4, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
        Bsp_t_Led5.t_Output.fnp_SetMode(&Bsp_t_Led5, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
        Bsp_t_Led6.t_Output.fnp_SetMode(&Bsp_t_Led6, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
    }
    else
    {
        uc_LedDebugEnable = 0;
        Bsp_t_Led1.t_Output.fnp_SetMode(&Bsp_t_Led1, BSP_LED_E_MODE_NULL, BSP_LED_E_PRIORITY_HIGH);
        Bsp_t_Led2.t_Output.fnp_SetMode(&Bsp_t_Led2, BSP_LED_E_MODE_NULL, BSP_LED_E_PRIORITY_HIGH);
        Bsp_t_Led3.t_Output.fnp_SetMode(&Bsp_t_Led3, BSP_LED_E_MODE_NULL, BSP_LED_E_PRIORITY_HIGH);
        Bsp_t_Led4.t_Output.fnp_SetMode(&Bsp_t_Led4, BSP_LED_E_MODE_NULL, BSP_LED_E_PRIORITY_HIGH);
        Bsp_t_Led5.t_Output.fnp_SetMode(&Bsp_t_Led5, BSP_LED_E_MODE_NULL, BSP_LED_E_PRIORITY_HIGH);
        Bsp_t_Led6.t_Output.fnp_SetMode(&Bsp_t_Led6, BSP_LED_E_MODE_NULL, BSP_LED_E_PRIORITY_HIGH);
    }
}
/********************************END OF FILE***********************************/
